#include <bits/stdc++.h>
using namespace std;
int INF = 1000000007;
using Graph = vector<vector<int>>;
int A[100050] = {}, B[100050] = {};
int N, taka, ao;
vector<bool> seen, seen1;
void dfs(const Graph &G, int v) {
  seen[v] = true;
  for (auto next_v : G[v]) {
    if (seen[next_v]) continue;
    A[next_v] = A[v] + 1;
    if (A[next_v] >= B[next_v]) continue;
    dfs(G, next_v);
  }
}
void dfs1(const Graph &G, int v) {
  seen1[v] = true;
  for (auto next_v : G[v]) {
    if (seen1[next_v]) continue;
    B[next_v] = B[v] + 1;
    dfs1(G, next_v);
  }
}
int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cin >> N >> taka >> ao;
  A[taka] = 0;
  B[ao] = 0;
  Graph G(N + 1);
  for (int i = 0; i < N - 1; i++) {
    int A, B;
    cin >> A >> B;
    G[A].push_back(B);
    G[B].push_back(A);
  }
  for (int i = 1; i <= N; i++) A[i] = -1;
  seen1.assign(N + 1, false);
  dfs1(G, ao);
  seen.assign(N + 1, false);
  dfs(G, taka);
  int ans1 = 0;
  for (int i = 1; i <= N; i++) {
    int Z{};
    if (A[i] == -1) {
      Z = 0;
    } else if (A[i] > B[i]) {
      Z = 0;
    } else {
      Z = B[i] - 1;
    }
    ans1 = max(ans1, Z);
  }
  cout << ans1 << endl;
}
