#include <bits/stdc++.h>
using namespace std;
bool prime(long long n) {
  for (long long i = 2; i <= sqrt(n); i++) {
    if (n % i == 0) return false;
  }
  return n != 1;
}
long long gcd(long long x, long long y) {
  if (y == 0) return x;
  return gcd(y, x % y);
}
long long lcm(long long x, long long y) { return x / gcd(x, y) * y; }
long long mod_pow(long long n, long long p, long long m) {
  if (p == 0) return 1;
  if (p % 2 == 0) {
    long long t = mod_pow(n, p / 2, m);
    return (t * t) % m;
  }
  return n * mod_pow(n, p - 1, m) % m;
}
long long extGCD(long long a, long long b, long long& x, long long& y) {
  if (b == 0) {
    x = 1;
    y = 0;
    return a;
  }
  long long d = extGCD(b, a % b, y, x);
  y -= a / b * x;
  return d;
}
long long modinv(long long a, long long m) {
  long long b = m, u = 1, v = 0;
  while (b) {
    long long t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}
long long digit(long long x) {
  long long cnt = 0;
  while (x > 0) {
    cnt += x % 10;
    x /= 10;
  }
  return cnt;
}
vector<long long> vec[100005];
long long va[100005];
long long bou[100005];
signed main() {
  long long n, u, v;
  cin >> n >> u >> v;
  u--, v--;
  long long a[100005], b[100005];
  for (long long i = 0; i < n - 1; i++) {
    cin >> a[i] >> b[i];
    a[i]--, b[i]--;
    vec[a[i]].push_back(b[i]);
    vec[b[i]].push_back(a[i]);
  }
  for (long long i = 0; i < n; i++) va[i] = -1;
  queue<long long> que;
  que.push(v);
  va[v] = 0;
  while (!que.empty()) {
    long long now = que.front();
    que.pop();
    for (long long i = 0; i < vec[now].size(); i++) {
      if (va[vec[now][i]] == -1) {
        que.push(vec[now][i]);
        va[vec[now][i]] = va[now] + 1;
      }
    }
  }
  queue<pair<long long, long long> > visit;
  visit.push({u, 0});
  long long before = 0;
  while (1) {
    pair<long long, long long> now = visit.front();
    bou[now.second] = max(bou[now.second], va[now.first]);
    visit.pop();
    if (before - 2 > now.second) {
      continue;
    }
    for (long long i = 0; i < vec[now.first].size(); i++) {
      if (before != now.second) {
        if (bou[before] == before - 1) {
          cout << before - 1 << endl;
          return 0;
        }
        if (bou[before] == before) {
          cout << before << endl;
          return 0;
        }
        before++;
      }
      visit.push({vec[now.first][i], before + 1});
    }
  }
  return 0;
}
