#include <bits/stdc++.h>
using namespace std;
const int maxn = 100010;
int n, a, b, u, v, r;
int head[maxn], tot;
int ans[maxn], deep[maxn];
struct fn {
  int nxt, to;
} f[maxn];
void add(int u, int v) {
  f[++tot].nxt = head[u];
  f[tot].to = v;
  head[u] = tot;
}
void dfs1(int x, int y) {
  deep[x] = deep[y] + 1;
  ans[x] = deep[x];
  for (int i = head[x]; i; i = f[i].nxt) {
    if (f[i].to == y) continue;
    dfs1(f[i].to, x);
    ans[x] = max(ans[x], ans[f[i].to]);
  }
}
int dfs2(int x, int y, int now) {
  if (now >= deep[x]) return 0;
  for (int i = head[x]; i; i = f[i].nxt) {
    if (f[i].to == y) continue;
    if (!dfs2(f[i].to, x, now = 1)) {
      r = x;
    }
  }
  return 1;
}
int main() {
  cin >> n;
  cin >> a >> b;
  for (int i = 1; i <= n - 1; i++) {
    cin >> u >> v;
    add(u, v);
    add(v, u);
  }
  dfs1(b, 0);
  dfs2(a, 0, 0);
  cout << ans[r] - 2;
  return 0;
}
