#include <bits/stdc++.h>
int const MAXN = 1e5;
int const INF = 3e5;
int par[MAXN], u, v, N;
std::vector<int> G[MAXN];
int dfs(int x, int p) {
  par[x] = p;
  int dist = INF;
  if (x == u) return 0;
  for (auto c : G[x])
    if (c != p) {
      dist = std::min(dist, dfs(c, x));
    }
  return dist + 1;
}
int dfs2(int x) {
  int dist = 0;
  for (auto c : G[x])
    if (c != par[x]) {
      dist = std::max(dist, dfs2(c) + 1);
    }
  return dist;
}
int main() {
  std::cin >> N >> u >> v;
  --u;
  --v;
  for (int i = 0; i < N - 1; ++i) {
    int A, B;
    std::cin >> A >> B;
    --A;
    --B;
    G[A].push_back(B);
    G[B].push_back(A);
  }
  int n = dfs(v, -1);
  for (int i = 0; i < (n - 1) / 2; ++i) u = par[u];
  int ans = dfs2(u) + n - (n - 1) / 2 - 1;
  std::cout << ans << std::endl;
  return 0;
}
