#include <bits/stdc++.h>
using namespace std;
vector<long long> adj[100005];
long long a[100005], lvl[100005], p[100005][20], h[100005];
long long ans = 0, A, T;
void dfs(long long u, long long par) {
  h[u] = 0;
  p[u][0] = par;
  lvl[u] = lvl[par] + 1;
  for (auto v : adj[u]) {
    if (v == par) continue;
    dfs(v, u);
    h[u] = max(h[u], h[v] + 1);
  }
}
long long lca(long long u, long long v) {
  long long i, lg;
  if (lvl[u] < lvl[v]) swap(u, v);
  for (lg = 0; (1 << lg) <= lvl[u]; lg++)
    ;
  lg--;
  for (i = lg; i >= 0; i--) {
    if ((lvl[u] - (1 << i)) >= lvl[v]) u = p[u][i];
  }
  if (u == v) return u;
  for (i = lg; i >= 0; i--) {
    if (p[u][i] != -1 && p[u][i] != p[v][i]) {
      u = p[u][i];
      v = p[v][i];
    }
  }
  return p[u][0];
}
long long getAncestor(long long u, long long dis) {
  dis = lvl[u] - dis;
  long long i, lg;
  for (lg = 0; (1 << lg) <= lvl[u]; lg++)
    ;
  lg--;
  for (i = lg; i >= 0; i--) {
    if (lvl[u] - (1 << i) >= dis) u = p[u][i];
  }
  return u;
}
long long dis(long long u, long long v) {
  if (lvl[u] < lvl[v]) swap(u, v);
  long long w = lca(u, v);
  return lvl[u] + lvl[v] - 2 * lvl[w];
}
int main() {
  long long i, u, v, j, n, x, y;
  cin >> n >> T >> A;
  for (i = 1; i < n; i++) {
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  for (i = 0; i < 20; i++) {
    for (j = 1; j <= n; j++) {
      p[j][i] = -1;
    }
  }
  lvl[0] = -1;
  dfs(A, 0);
  for (i = 1; i < 20; i++) {
    for (j = 1; j <= n; j++) {
      if (p[j][i - 1] != -1) p[j][i] = p[p[j][i - 1]][i - 1];
    }
  }
  if (p[T][0] == A) {
    cout << 0;
    return 0;
  }
  long long cur = T;
  x = 0;
  long long mv = T, mx = 0;
  while (cur != A) {
    if (dis(T, cur) >= dis(A, cur)) break;
    if (x + h[cur] > mx) {
      mx = x + h[cur];
      mv = cur;
    }
    x++;
    cur = p[cur][0];
  }
  y = mv;
  while (y != A) {
    ans++;
    y = p[y][0];
  }
  ans += max(0LL, h[mv] - 1);
  cout << ans;
}
