#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e16 + 18;
const long long MAX = 100005;
const long long MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return true;
  }
  return false;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) {
  return s << "(" << p.first << ", " << p.second << ")";
}
template <typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i];
    if (i < len - 1) s << "	";
  }
  return s;
}
template <typename T>
ostream &operator<<(ostream &s, const vector<vector<T>> &vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
    s << vv[i] << endl;
  }
  return s;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << std::setprecision(10);
  long long n, u, v;
  cin >> n >> u >> v;
  vector<vector<long long>> g(n);
  u--;
  v--;
  for (long long i = (0); i < (n - 1); i++) {
    long long a, b;
    cin >> a >> b;
    a--;
    b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  vector<long long> par(n, -1);
  queue<pair<int, int>> q;
  q.push(make_pair(v, 0));
  vector<long long> distv(n, 0);
  while (!q.empty()) {
    pair<int, int> &now = q.front();
    q.pop();
    for (auto &next : g[now.first]) {
      if (next == v) continue;
      if (distv[next] != 0) continue;
      distv[next] = now.second + 1;
      par[next] = now.first;
      q.push(make_pair(next, now.second + 1));
    }
  }
  vector<long long> distu(n, 0);
  q.push(make_pair(u, 0));
  while (!q.empty()) {
    pair<int, int> &now = q.front();
    q.pop();
    for (auto &next : g[now.first]) {
      if (next == u) continue;
      if (distu[next] != 0) continue;
      distu[next] = now.second + 1;
      q.push(make_pair(next, now.second + 1));
    }
  }
  long long ans = 0;
  sort(par.begin(), par.end());
  for (long long i = (0); i < (n); i++) {
    long long x = abs(distv[i] - distu[i]);
    if (binary_search(par.begin(), par.end(), i)) {
      if (x == 0 || x == 1) {
        distv[i];
        chmax(ans, distv[i]);
      }
    }
  }
  cout << ans << endl;
  return 0;
}
