#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
const int oo = 0x3f3f3f3f;
vector<int> g[N];
int dx[N], dy[N];
void dfs(int u, int* d, int p = 0) {
  d[u] = d[p] + 1;
  for (int v : g[u])
    if (v != p) {
      dfs(v, d, u);
    }
}
int(((((main)))))() < % ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, x, y;
cin >> n >> x >> y;
for (int i = 1; i < n; i++) {
  int u, v;
  cin >> u >> v;
  g[u].emplace_back(v);
  g[v].emplace_back(u);
}
dx[0] = -1;
dy[0] = -1;
dfs(x, dx);
dfs(y, dy);
int ans = 0;
int same = oo;
for (int u = 1; u <= n; u++) {
  ;
  if (dx[u] < dy[u]) ans = max(ans, dx[u]);
  if (dx[u] == dy[u]) same = min(same, dx[u]);
};
if (same < oo) ans = max(ans, same);
cout << ans << '\n';
return 0;
% >
