#include <bits/stdc++.h>
using namespace std;
const int maxn = 500010;
struct eage {
  int t, nex;
} e[2 * maxn];
int depth[maxn], father[maxn][25], lg[maxn], head[maxn], son[maxn];
int tmp = 0;
int n, s, u, v;
void build(int x, int y) {
  tmp++;
  e[tmp].t = y;
  e[tmp].nex = head[x];
  head[x] = tmp;
}
void dfs(int now, int fa) {
  depth[now] = depth[fa] + 1;
  father[now][0] = fa;
  for (int i = 1; (1 << i) <= depth[now]; i++) {
    father[now][i] = father[father[now][i - 1]][i - 1];
  }
  for (int i = head[now]; i > 0; i = e[i].nex) {
    if (e[i].t != fa) dfs(e[i].t, now);
  }
}
int lca(int x, int y) {
  if (depth[x] < depth[y]) {
    swap(x, y);
  }
  while (depth[x] > depth[y]) x = father[x][lg[depth[x] - depth[y]] - 1];
  if (x == y) return x;
  for (int i = lg[depth[x] - 1]; i >= 0; i--) {
    if (father[x][i] != father[y][i]) {
      x = father[x][i];
      y = father[y][i];
    }
  }
  return father[y][0];
}
int fson(int x) {
  if (!son[x]) return x;
  return fson(son[x]);
}
int main() {
  cin >> n >> u >> v;
  s = 1;
  int a, b, ans = 0;
  for (int i = 1; i < n; i++) {
    scanf("%d%d", &a, &b);
    son[a] = b;
    build(a, b);
    build(b, a);
  }
  dfs(s, 0);
  for (int i = 1; i <= n; i++) lg[i] = lg[i - 1] + (1 << lg[i - 1] == i);
  if (lca(u, v) != u && lca(u, v) != v) ans = depth[u] - depth[lca(u, v)];
  u = lca(u, v);
  if (depth[v] > depth[fson(v)] - depth[v]) {
    ans += depth[u];
  } else {
    ans += depth[fson(v)] - depth[v];
  }
  cout << ans - 1;
}
