#include <bits/stdc++.h>
using namespace std;
using vvi = vector<vector<int>>;
int du[101010], dv[101010], duv[101010];
void bfs(vvi &G, int s, int *d) {
  queue<int> q;
  d[s] = 0;
  q.push(s);
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (auto &e : G[u]) {
      if (d[e] > 0) continue;
      if (d[e] == 0 && e != s) d[e] = d[u] + 1, q.push(e);
    }
  }
  return;
}
int main() {
  int N, u, v;
  scanf("%d %d %d", &N, &u, &v);
  u--, v--;
  vvi G(N);
  for (int i = 0; i < N - 1; i += 1) {
    int a, b;
    scanf("%d %d", &a, &b);
    a--, b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  bfs(G, u, du);
  bfs(G, v, dv);
  int m = -1, dm = du[v] / 2;
  for (int i = 0; i < N; i += 1) {
    if (du[i] == dm && dv[i] == dm) {
      m = i;
      break;
    }
  }
  bfs(G, m, duv);
  int f = -1, df = 0;
  for (int i = 0; i < N; i += 1) {
    if (df < duv[i] && du[i] < dv[i]) f = i, df = max(df, duv[i]);
  }
  printf("%d\n", duv[v] + duv[f] - 1);
  return 0;
}
