#include <bits/stdc++.h>
using namespace std;
int main() {
  long long N, u, v;
  cin >> N >> u >> v;
  u--;
  v--;
  vector<long long> u_depth(N, -1), v_depth(N, -1);
  u_depth[u] = 0;
  v_depth[v] = 0;
  vector<queue<long long>> can(N);
  vector<queue<long long>> can2(N);
  long long A, B;
  for (int i = 0; i < N - 1; i++) {
    cin >> A >> B;
    A--;
    B--;
    can[A].push(B);
    can[B].push(A);
    can2[A].push(B);
    can2[B].push(A);
  }
  queue<long long> que;
  que.push(u);
  long long pla = u;
  while (!que.empty()) {
    pla = que.front();
    while (!can[pla].empty()) {
      if (u_depth[can[pla].front()] == -1) {
        u_depth[can[pla].front()] = u_depth[pla] + 1;
      }
      que.push(can[pla].front());
      can[pla].pop();
    }
    que.pop();
  }
  queue<long long> que2;
  que2.push(v);
  pla = v;
  while (!que2.empty()) {
    pla = que2.front();
    while (!can2[pla].empty()) {
      if (v_depth[can2[pla].front()] == -1) {
        v_depth[can2[pla].front()] = v_depth[pla] + 1;
      }
      que2.push(can2[pla].front());
      can2[pla].pop();
    }
    que2.pop();
  }
  long long ans = 0;
  for (int i = 0; i < N; i++) {
    if (u_depth[i] == v_depth[i]) {
      ans = max(ans, v_depth[i]);
    }
    if (u_depth[i] < v_depth[i]) {
      ans = max(ans, (v_depth[i] - ((v_depth[i] - u_depth[i]) % 2)));
    }
  }
  for (int i = 0; i < N; i++) {
    cerr << u_depth[i] << " " << v_depth[i] << endl;
  }
  cout << ans << endl;
}
