#include <bits/stdc++.h>
using namespace std;
int N, U, V;
vector<int> E[100010];
int dU[100010], dV[100010];
int main() {
  cin >> N >> U >> V;
  U--;
  V--;
  for (int i = 0; i < N - 1; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    E[a].push_back(b);
    E[b].push_back(a);
  }
  fill(dU, dU + N, -1);
  fill(dV, dV + N, -1);
  dU[U] = 0;
  dV[V] = 0;
  queue<int> que;
  que.push(U);
  while (que.size()) {
    int p = que.front();
    que.pop();
    for (int i = 0; i < E[p].size(); i++) {
      if (dU[E[p].at(i)] == -1) {
        dU[E[p].at(i)] = dU[p] + 1;
        que.push(E[p].at(i));
      }
    }
  }
  que.push(V);
  while (que.size()) {
    int p = que.front();
    que.pop();
    for (int i = 0; i < E[p].size(); i++) {
      if (dV[E[p].at(i)] == -1) {
        dV[E[p].at(i)] = dV[p] + 1;
        que.push(E[p].at(i));
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < N; i++) {
    if (dU[i] < dV[i]) ans = dV[i];
  }
  cout << ans - 1 << endl;
}
