#include<iostream>
#include<algorithm>
#include<vector>

int const MAXN = 1e5;
int const INF = 3e5;

// u: escape, v: chase
int par[MAXN], u, v, N;
std::vector<int> G[MAXN];

int dfs(int x, int p) {
  par[x] = p;
  int dist = INF;
  for(auto c: G[x]) if(c != p) {
    dist = std::min(dist, dfs(c, x)); 
  }
  if(x == u) return 0;
  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;
}
