#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
const int MOD = 1000000007;
int main() {
  ll N, u, v;
  cin >> N >> u >> v;
  u--;
  v--;
  vector<ll> A(N - 1), B(N - 1);
  for (int i = 0; i < N - 1; i++) {
    cin >> A[i] >> B[i];
    A[i]--;
    B[i]--;
  }
  vector<ll> distance(N, -1);
  vector<ll> done(N, 0);
  vector<vector<ll> > next(N);
  for (int i = 0; i < N - 1; i++) {
    next[A[i]].push_back(B[i]);
    next[B[i]].push_back(A[i]);
  }
  for (int i = 0; i < N; i++) {
    if (next[i].size() == 1 && i != v) {
      distance[i] = 0;
      done[i] = 1;
    }
  }
  while (true) {
    bool allDone = true;
    for (int i = 0; i < N; i++) {
      if (i == v) continue;
      if ((next[i].size() == 1 && done[i] >= 1) ||
          done[i] >= next[i].size() - 1) {
        for (int j = 0; j < next[i].size(); j++) {
          if (done[next[i][j]] <= next[next[i][j]].size() - 1) {
            distance[next[i][j]] = max(distance[next[i][j]], distance[i] + 1);
            done[next[i][j]]++;
          }
        }
      } else
        allDone = false;
    }
    if (allDone) break;
  }
  cout << distance[v] - 1 << endl;
  return 0;
}
