#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > ad(100005);
int po[20], ar[4 * 100005], lev[100005], sp[2 * 100005][20], vp[2 * 100005],
    fist[100005], vis[100005];
int C;
void pre() {
  int i, k;
  ar[1] = 0, k = 1, po[0] = 1;
  while (k < 2 * 100005) {
    for (i = k + 1; i < 2 * k; i++) ar[i] = ar[k];
    ar[2 * k] = 1 + ar[k], k *= 2;
  }
  for (i = 1; i < 20; i++) po[i] = 2 * po[i - 1];
  return;
}
void dfs(int s) {
  fist[s] = C, vp[C] = s, C++, vis[s] = 1;
  int a, i, x = ad[s].size();
  for (i = 0; i < x; i++) {
    a = ad[s][i];
    if (vis[a] == 0) lev[a] = lev[s] + 1, dfs(a), vp[C] = s, C++;
  }
  return;
}
void build() {
  int j, k;
  for (j = C - 1; j >= 0; j--) {
    sp[j][0] = vp[j];
    for (k = 1; j + po[k] <= C; k++)
      sp[j][k] = lev[sp[j][k - 1]] < lev[sp[j + po[k - 1]][k - 1]]
                     ? sp[j][k - 1]
                     : sp[j + po[k - 1]][k - 1];
  }
  return;
}
int lca(int u, int v) {
  int a = fist[u], b = fist[v];
  if (a > b) swap(a, b);
  int y, x = b - a + 1;
  y = ar[x], x -= po[y];
  return lev[sp[a][y]] < lev[sp[a + x][y]] ? sp[a][y] : sp[a + x][y];
}
int dist(int u, int v) {
  int z = lca(u, v);
  return lev[u] + lev[v] - 2 * lev[z];
}
int main() {
  int n, q, i, a, b, x, y;
  scanf("%d", &n);
  scanf("%d", &x), scanf("%d", &y);
  pre();
  for (i = 1; i < n; i++) {
    scanf("%d", &a), scanf("%d", &b);
    ad[a].push_back(b);
    ad[b].push_back(a);
  }
  lev[1] = 0;
  dfs(1);
  build();
  a = 0;
  for (i = 1; i <= n; i++) a = max(a, dist(i, y));
  printf("%d\n", a - 1);
}
