#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int n, u, v, tot, lev[N], dep[N], lg[N], fa[N][20], head[N], nex[N << 1],
    to[N << 1];
void add(int u, int v) {
  to[++tot] = v;
  nex[tot] = head[u];
  head[u] = tot;
}
void dfs(int u, int p) {
  dep[u] = dep[p] + 1;
  fa[u][0] = p;
  for (int i = 1; 1 << i <= dep[p]; i++) fa[u][i] = fa[fa[u][i - 1]][i - 1];
  lev[u] = true;
  for (int i = head[u]; i; i = nex[i]) {
    int v = to[i];
    if (v == p) continue;
    dfs(v, u);
    lev[u] = false;
  }
}
int LCA(int u, int v) {
  if (dep[u] < dep[v]) swap(u, v);
  while (dep[u] > dep[v]) u = fa[u][lg[dep[u] - dep[v]]];
  if (u == v) return u;
  for (int i = lg[dep[u]]; i >= 0; i--)
    if (fa[u][i] != fa[v][i]) u = fa[u][i], v = fa[v][i];
  return fa[u][0];
}
int DIS(int u, int v) { return dep[u] + dep[v] - 2 * dep[LCA(u, v)]; }
int main() {
  for (int i = 1; i < N; i++) lg[i] = lg[i - 1] + (1 << lg[i - 1] == i);
  for (int i = 1; i < N; i++) lg[i]--;
  scanf("%d%d%d", &n, &u, &v);
  for (int i = 1; i < n; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    add(u, v);
    add(v, u);
  }
  dfs(1, 0);
  int ans = 0;
  for (int i = 1; i <= n; i++)
    if (lev[i]) {
      int lca = LCA(u, i);
      if (DIS(u, lca) > DIS(u, v) / 2 + DIS(u, v) % 2) continue;
      int len = DIS(v, i) - 1;
      ans = max(ans, len);
    }
  cout << ans;
}
