#include <bits/stdc++.h>
using namespace std;
const long long nmax = 1e9 + 7;
const long long mod = 998244353;
const long long INF = 1e18;
const double PI = 2 * asin(1);
int main() {
  int N, U, V;
  cin >> N >> U >> V;
  U--;
  V--;
  vector<int> graph[N];
  for (int i = 0; i < N - 1; i++) {
    int A, B;
    cin >> A >> B;
    A--;
    B--;
    graph[A].push_back(B);
    graph[B].push_back(A);
  }
  vector<int> distU(N), distV(N);
  queue<int> que;
  que.push(U);
  vector<bool> visitedU(N), visitedV(N);
  visitedU[U] = true;
  visitedV[V] = true;
  while (!que.empty()) {
    int now = que.front();
    que.pop();
    for (int i = 0; i < graph[now].size(); i++) {
      int next = graph[now][i];
      if (visitedU[next] == false) {
        que.push(next);
        visitedU[next] = true;
        distU[next] = distU[now] + 1;
      }
    }
  }
  que.push(V);
  while (!que.empty()) {
    int now = que.front();
    que.pop();
    for (int i = 0; i < graph[now].size(); i++) {
      int next = graph[now][i];
      if (visitedV[next] == false) {
        que.push(next);
        visitedV[next] = true;
        distV[next] = distV[now] + 1;
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < N; i++) {
    ans = max(ans, min(distU[i], distV[i] - 1));
  }
  cout << ans << endl;
  return 0;
}
