#include <bits/stdc++.h>
using namespace std;
int n, pre[100005], S, T, cnt, dis[100005], maxdis[100005], fa[100005], lp,
    lpdis;
struct edge {
  int u, v, nex;
} e[100005 << 1];
void addedge(int u, int v) {
  e[cnt].u = u;
  e[cnt].v = v;
  e[cnt].nex = pre[u];
  pre[u] = cnt++;
}
void dfs(int u, int father, int dep) {
  dis[u] = dep;
  maxdis[u] = dep;
  fa[u] = father;
  if (lpdis < dis[u]) {
    lp = u;
    lpdis = dep;
  }
  for (int i = pre[u]; ~i; i = e[i].nex) {
    int v = e[i].v;
    if (v == father) continue;
    dfs(v, u, dep + 1);
    maxdis[u] = max(maxdis[u], maxdis[v]);
  }
}
int lca(int u, int v) {
  while (u != v) {
    if (dis[u] > dis[v])
      u = fa[u];
    else
      v = fa[v];
  }
  return u;
}
int main() {
  memset(pre, -1, sizeof(pre));
  scanf("%d%d%d", &n, &S, &T);
  for (int i = 1; i < n; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    addedge(u, v);
    addedge(v, u);
  }
  dfs(T, -1, 0);
  int ans = dis[S] - 1 + maxdis[S] - dis[S];
  int LCA = lca(S, lp);
  if (lpdis != dis[S]) {
    if (dis[LCA] > dis[S] - dis[LCA]) {
      int rem = dis[LCA] - (dis[S] - dis[LCA]);
      ans = max(ans, dis[S] - dis[LCA] + rem - 1 + maxdis[LCA] - dis[LCA]);
    }
  }
  printf("%d\n", ans);
  return 0;
}
