#include <bits/stdc++.h>
#pragma target("avx")
using namespace std;
const int INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
const long long LINF = 1e18;
int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
long long n, cnt, ans, a[ohara], b[ohara], c, d, tmp, m, h, w, x, y, sum, k, q,
    u, v;
long long ta[ohara], ao[ohara];
vector<long long> g[ohara];
bool vi[ohara];
void dfs1(long long now, long long dep) {
  if (ta[now] != -1) return;
  ta[now] = dep;
  for (long long(i) = 0; (i) < (int)((g[now]).size()); (i)++) {
    long long to = g[now][i];
    dfs1(to, dep + 1);
  }
}
void dfs2(long long now, long long dep) {
  if (ao[now] != -1) return;
  ao[now] = dep;
  for (long long(i) = 0; (i) < (int)((g[now]).size()); (i)++) {
    long long to = g[now][i];
    dfs2(to, dep + 1);
  }
}
void dfs(long long now) {
  if (vi[now]) return;
  vi[now] = true;
  if (ta[now] < ao[now]) {
    ans = max(ans, ta[now]);
    for (long long(i) = 0; (i) < (int)((g[now]).size()); (i)++) {
      long long to = g[now][i];
      dfs(to);
    }
  } else {
    if (ta[now] == ao[now]) ans = max(ans, ta[now]);
  }
}
int main(void) {
  cin.tie(0);
  cout.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> u >> v;
  u--;
  v--;
  for (long long(i) = 0; (i) < (int)(n - 1); (i)++) {
    cin >> a[i] >> b[i];
    a[i]--;
    b[i]--;
    g[a[i]].push_back(b[i]);
    g[b[i]].push_back(a[i]);
  }
  for (long long(i) = 0; (i) < (int)(ohara); (i)++) ta[i] = -1, ao[i] = -1;
  dfs1(u, 0LL);
  dfs2(v, 0LL);
  dfs(u);
  cout << (ans) << endl;
  return 0;
}
