#include <bits/stdc++.h>
using namespace std;
long long int N, u, v;
long long int A[100005], B[100005];
struct dijkstra_normal {
  long long int V;
  long long int *d;
  vector<pair<long long int, long long int> > *edges;
  priority_queue<pair<long long int, long long int>,
                 vector<pair<long long int, long long int> >,
                 greater<pair<long long int, long long int> > >
      q;
  dijkstra_normal(long long int N) : V(N) {
    d = new long long int[N];
    edges = new vector<pair<long long int, long long int> >[N];
    for (long long int i = 0; i < N; i++) {
      d[i] = 1001001001001001001;
    }
  }
  void push(long long int a, long long int b, long long int c) {
    edges[a].push_back(make_pair(b, c));
  }
  long long int *solve(long long int start) {
    q.push(make_pair(0, start));
    while (!q.empty()) {
      pair<long long int, long long int> p = q.top();
      q.pop();
      long long int now = p.second;
      long long int cost = p.first;
      if (d[now] <= cost) continue;
      d[now] = cost;
      for (long long int e = 0; e < edges[now].size(); e++) {
        long long int to = edges[now][e].first;
        long long int cst = edges[now][e].second;
        if (d[to] > cost + cst) {
          d[to] > cost + cst;
          q.push(make_pair(cost + cst, to));
        }
      }
    }
    return d;
  }
  vector<long long int> return_not_use() {
    delete[] edges;
    delete[] d;
  }
};
signed main() {
  scanf("%lld %lld %lld", &N, &u, &v);
  u--;
  v--;
  dijkstra_normal dijk(N);
  for (long long int i = 0; i < N - 1; i++) {
    scanf("%lld %lld", &A[i], &B[i]);
    A[i]--;
    B[i]--;
    dijk.push(A[i], B[i], 1);
    dijk.push(B[i], A[i], 1);
  }
  long long int ans = 0;
  long long int *d = dijk.solve(v);
  long long int *d2 = dijk.solve(u);
  for (long long int i = 0; i < N; i++) {
    if (d[i] >= d2[i] && d[i] > ans) ans = d[i];
  }
  printf("%lld\n", ans);
  return 0;
}
