#include <bits/stdc++.h>
using namespace std;
vector<int> G[200010];
int Aoki[200010];
void dfs1(int now, int back = -1, int t = 0) {
  Aoki[now] = t;
  for (int to : G[now]) {
    if (to == back) continue;
    dfs1(to, now, t + 1);
  }
}
int dfs2(int now, int back = -1, int t = 0) {
  if (Aoki[now] <= t) {
    return Aoki[now];
  }
  bool isleaf = true;
  int res = 0;
  for (int to : G[now]) {
    if (to == back) continue;
    res = max(res, dfs2(to, now, t + 1));
    isleaf = false;
  }
  if (isleaf) res = max(res, min(Aoki[now], t));
  return res;
}
int main() {
  int N, u, v;
  scanf("%d%d%d", &N, &u, &v);
  u--;
  v--;
  for (int i = 0; i < N - 1; i++) {
    int A, B;
    scanf("%d%d", &A, &B);
    A--;
    B--;
    G[A].push_back(B);
    G[B].push_back(A);
  }
  dfs1(v);
  int ans = dfs2(u);
  cout << ans << endl;
  return 0;
}
