#include <bits/stdc++.h>
using namespace std;
int N, taka, ao;
vector<int> G[100005];
int dis[100005];
void dfs(int v, int k) {
  dis[v] = k;
  for (auto i : G[v]) {
    if (dis[i] == -1) {
      dfs(i, k + 1);
    }
  }
}
int flag[100005];
void dfs_2(int v, int k) {
  flag[v] = k;
  for (auto i : G[v]) {
    if (flag[i] == 0) {
      if (i != ao) {
        dfs_2(i, k);
      } else {
        dfs_2(i, -k);
      }
    }
  }
}
int main() {
  cin >> N >> taka >> ao;
  taka--;
  ao--;
  for (int i = 0; i < N - 1; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  for (int i = 0; i < 100005; i++) dis[i] = -1;
  dfs(ao, 0);
  dfs_2(taka, 1);
  int st_dis = dis[taka];
  if (st_dis == 0) {
    cout << 0 << endl;
    return 0;
  }
  int ans = 0;
  for (int i = 0; i < N; i++) {
    if (flag[i] == 1) {
      ans = max(ans, dis[i]);
    }
  }
  ans--;
  cout << ans << endl;
}
