#include <bits/stdc++.h>
const int N = 1e5 + 10;
int n, U, V, no, res, now;
int cnt, tot1, tot2, tot;
int first[N], dep[N], fa[N];
int A[N], B[N], ans[N];
struct edge {
  int to, _next;
} e[N << 1];
inline int read() {
  register int x = 0, f = 0, ch;
  while (!isdigit(ch = getchar())) f |= ch == '-';
  while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
  return f ? -x : x;
}
void Add_Edge(int u, int v) {
  e[cnt].to = v;
  e[cnt]._next = first[u];
  first[u] = cnt++;
}
void dfs(int x, int p) {
  dep[x] = dep[p] + 1;
  fa[x] = p;
  now = std::max(res, dep[x]);
  for (register int i = first[x], y = e[i].to; ~i; i = e[i]._next, y = e[i].to)
    if (y != p) dfs(y, x);
}
int main() {
  n = read(), U = read(), V = read();
  std::swap(U, V);
  memset(first, -1, sizeof(first));
  for (register int i = 1; i <= n - 1; ++i) {
    int u = read(), v = read();
    Add_Edge(u, v);
    Add_Edge(v, u);
  }
  dfs(1, 0);
  while (dep[U] > dep[V]) {
    A[++tot1] = U;
    U = fa[U];
  }
  while (dep[V] > dep[U]) {
    B[++tot2] = V;
    V = fa[V];
  }
  while (U != V) {
    A[++tot1] = U;
    B[++tot2] = V;
    U = fa[U];
    V = fa[V];
  }
  for (register int i = 1; i <= tot1; ++i) ans[++tot] = A[i];
  ans[++tot] = U;
  for (register int i = tot2; i >= 1; --i) ans[++tot] = B[i];
  memset(dep, 0, sizeof(dep));
  res = 0;
  if (tot == 2) {
    puts("0");
    return 0;
  }
  if (tot & 1) {
    res += tot / 2 - 1;
    dfs(ans[tot / 2 + 2], ans[tot / 2 + 1]);
  } else {
    res += tot / 2 - 1;
    dfs(ans[tot / 2 + 2], ans[tot / 2 + 1]);
  }
  printf("%d", now + res);
  return 0;
}
