#include <bits/stdc++.h>
using namespace std;
signed main() {
  long long N, t, a;
  cin >> N >> t >> a;
  vector<vector<long long> > Ki(N);
  for (long long i = (long long)(0); i < (long long)(N - 1); i++) {
    long long X, Y;
    cin >> X >> Y;
    Ki[X - 1].push_back(Y - 1);
    Ki[Y - 1].push_back(X - 1);
  }
  vector<long long> T(N, -1), A(N, -1);
  queue<long long> Q;
  Q.push(t - 1);
  Q.push(-1);
  long long count = 0;
  while (Q.size() > 1) {
    long long K = Q.front();
    Q.pop();
    if (K == -1) {
      count++;
      Q.push(-1);
    } else {
      T[K] = count;
      for (long long i = (long long)(0); i < (long long)(Ki[K].size()); i++) {
        if (Ki[K][i] == -1) Q.push(Ki[K][i]);
      }
    }
  }
  count = 0;
  Q.pop();
  Q.push(a - 1);
  Q.push(-1);
  while (Q.size() > 1) {
    long long K = Q.front();
    Q.pop();
    if (K == -1) {
      count++;
      Q.push(-1);
    } else {
      A[K] = count;
      for (long long i = (long long)(0); i < (long long)(Ki[K].size()); i++) {
        if (Ki[K][i] == -1) Q.push(Ki[K][i]);
      }
    }
  }
  long long ans = 0;
  for (long long i = (long long)(0); i < (long long)(N); i++) {
    if (T[i] >= A[i]) ans = max(ans, A[i] - 1);
  }
  cout << ans << endl;
}
