#include <bits/stdc++.h>
int main() {
  int N, u, v;
  scanf("%d%d%d", &N, &u, &v);
  u--;
  v--;
  using vi = std::vector<int>;
  using vvi = std::vector<vi>;
  vvi edges(N);
  for (int i{}; i < N - 1; i++) {
    int A, B;
    scanf("%d%d", &A, &B);
    A--;
    B--;
    edges[A].push_back(B);
    edges[B].push_back(A);
  }
  vi taka(N, 1 << 30), aoki(N, 1 << 30);
  taka[u] = aoki[v] = 0;
  std::queue<int> bfs;
  bfs.push(u);
  while (!bfs.empty()) {
    auto now{bfs.front()};
    bfs.pop();
    for (auto& e : edges[now]) {
      if (taka[e] != (1 << 30)) continue;
      taka[e] = taka[now] + 1;
      bfs.push(e);
    }
  }
  bfs.push(v);
  while (!bfs.empty()) {
    auto now{bfs.front()};
    bfs.pop();
    for (auto& e : edges[now]) {
      if (aoki[e] != (1 << 30)) continue;
      aoki[e] = aoki[now] + 1;
      bfs.push(e);
    }
  }
  int dist{aoki[u]};
  int ans{1 - dist % 2};
  if (dist % 2 == 1) {
    for (int i{}; i < N; i++) {
      if (aoki[i] <= taka[i] || aoki[i] + taka[i] == dist) continue;
      if (aoki[i] - taka[i] == dist)
        ans = std::max(ans, dist / 2 * 2 + taka[i]);
      else {
        int corner{(dist - (aoki[i] - taka[i])) / 2};
        ans = std::max(ans, dist / 2 * 2 + taka[i] - corner * 2);
      }
    }
  } else {
    for (int i{}; i < N; i++) {
      if (aoki[i] <= taka[i] || aoki[i] + taka[i] == dist) continue;
      if (aoki[i] - taka[i] == dist)
        ans = std::max(ans, (dist / 2 - 1) * 2 + taka[i] + 1);
      else {
        int corner{(dist - (aoki[i] - taka[i])) / 2};
        ans = std::max(ans, (dist / 2 - 1) * 2 + taka[i] + 1 - corner * 2);
      }
    }
  }
  printf("%d\n", ans);
  return 0;
}
