#include <bits/stdc++.h>
using namespace std;
int ans = 0;
vector<int> vt[100005];
vector<int> dist_oni(100005);
int N, niges, onis;
vector<int> tmp(100005, 0);
void solve(int depth, int now) {
  if (tmp[now] != 0 && tmp[now] >= depth) {
    return;
  }
  if (depth >= dist_oni[now]) {
    ans = max(ans, depth);
    return;
  }
  for (auto nx : vt[now]) {
    if (depth + 1 <= dist_oni[nx]) {
      solve(depth + 1, nx);
    }
  }
  ans = max(ans, depth);
  return;
}
int main() {
  cin >> N >> niges >> onis;
  niges--;
  onis--;
  for (int i = 0; i < N - 1; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    vt[a].push_back(b);
    vt[b].push_back(a);
  }
  vector<int> used(N, 0);
  fill(dist_oni.begin(), dist_oni.end(), 10000000);
  queue<int> que;
  que.push(onis);
  dist_oni[onis] = 0;
  while (!que.empty()) {
    int now = que.front();
    que.pop();
    used[now] = 1;
    for (auto nx : vt[now]) {
      if (used[nx] == 0) {
        dist_oni[nx] = dist_oni[now] + 1;
        que.push(nx);
      }
    }
  }
  solve(0, niges);
  cout << ans << endl;
  return 0;
}
