#include <bits/stdc++.h>
using namespace std;
int ans;
int n;
int sTakahashi, sAoki;
int aoki[100000];
vector<int> t[100000];
void createAoki(int cur, int dist) {
  aoki[cur] = dist;
  for (int i = 0; i < t[cur].size(); i++) {
    int next = t[cur][i];
    if (aoki[next] == -1) {
      createAoki(next, dist + 1);
    }
  }
}
void solve(int cur, int pre, int dist) {
  if (aoki[cur] >= dist) {
    ans = max(ans, dist);
  }
  if (aoki[cur] <= dist) {
    return;
  }
  ans = max(ans, dist);
  for (int i = 0; i < t[cur].size(); i++) {
    int next = t[cur][i];
    if (pre != next) {
      solve(next, cur, dist + 1);
    }
  }
}
int main() {
  while (cin >> n >> sTakahashi >> sAoki) {
    sTakahashi--;
    sAoki--;
    for (int i = 0; i < 100000; i++) {
      t[i].clear();
    }
    for (int i = 0; i < n - 1; i++) {
      int a, b;
      cin >> a >> b;
      a--;
      b--;
      t[a].push_back(b);
      t[b].push_back(a);
    }
    memset(aoki, -1, sizeof(aoki));
    createAoki(sAoki, 0);
    ans = 0;
    solve(sTakahashi, -1, 0);
    cout << ans << endl;
  }
}
