#include <bits/stdc++.h>
using namespace std;
int N, u, v, alpha, beta;
vector<vector<int>> G;
int a(int n, int u, int v);
int t(int n, int u, int v) {
  if (n >= N || u == v) return n;
  int ans = 0;
  for (int w : G[u]) {
    ans = max(ans, a(n, w, v));
    alpha = max(alpha, ans);
    if (beta <= alpha) continue;
  }
  return ans;
}
int a(int n, int u, int v) {
  if (n >= N || u == v) return n;
  int ans = 1e9;
  for (int w : G[v]) {
    ans = min(ans, t(n + 1, u, w));
    beta = min(beta, ans);
    if (beta <= alpha) continue;
  }
  return ans;
}
int main() {
  cin >> N >> u >> v;
  --u, --v;
  G.resize(N);
  for (int i = 0; i < (int)N - 1; ++i) {
    int A, B;
    cin >> A >> B;
    --A, --B;
    G[A].push_back(B);
    G[B].push_back(A);
  }
  alpha = 0, beta = 1e9;
  cout << t(0, u, v) << endl;
  return 0;
}
