#include <bits/stdc++.h>
int *dep, **e, *md, *fa, n, s, t, *elen;
void dfs(int u, int f) {
  dep[u] = md[u] = dep[f] + 1;
  fa[u] = f;
  for (size_t i = 0; i < elen[u]; i++) {
    if (e[u][i] != f) {
      dfs(e[u][i], u);
      md[u] = ((md[u] > md[e[u][i]]) ? md[u] : md[e[u][i]]);
    }
  }
}
int main() {
  scanf("%d%d%d", &n, &s, &t);
  e = (int **)calloc(n + 1, sizeof(int *));
  dep = (int *)calloc(n + 1, sizeof(int));
  md = (int *)calloc(n + 1, sizeof(int));
  elen = (int *)calloc(n + 1, sizeof(int));
  fa = (int *)calloc(n + 1, sizeof(int));
  for (size_t i = 0; i < n + 1; i++) {
    e[i] = (int *)calloc(n + 1, sizeof(int));
    dep[i] = md[i] = elen[i] = 0;
  }
  for (size_t i = 1; i < n; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    e[u][elen[u]++] = v;
    e[v][elen[v]++] = u;
  }
  dfs(t, 0);
  int ans = 0, x = s;
  while (dep[s] - dep[x] < dep[x] - dep[t]) {
    ans = ((ans > md[x] - 1) ? ans : md[x] - 1);
    x = fa[x];
  }
  printf("%d", ans - 1);
  return 0;
}
