#include <bits/stdc++.h>
int main() {
  int n, u, v;
  std::cin >> n >> u >> v;
  u--;
  v--;
  std::vector<std::vector<int>> graph(n);
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    std::cin >> a >> b;
    a--;
    b--;
    graph[a].push_back(b);
    graph[b].push_back(a);
  }
  int ans = 0;
  std::vector<int> vscore(n, -1), uscore(n, -1);
  std::queue<int> q;
  q.push(v);
  while (!q.empty()) {
    int place = q.front();
    q.pop();
    for (int i : graph[place]) {
      if (vscore[i] != -1) continue;
      q.push(i);
      vscore[i] = vscore[place] + 1;
    }
  }
  q.push(u);
  while (!q.empty()) {
    int place = q.front();
    q.pop();
    for (int i : graph[place]) {
      if (uscore[i] != 0) continue;
      q.push(i);
      uscore[i] = uscore[place] + 1;
    }
  }
  std::vector<bool> used(n, false);
  for (int i = 0; i < n; i++) {
    if (vscore[i] <= uscore[i]) used[i] = true;
  }
  for (int i = 0; i < n; i++)
    if (!used[i] && ans < vscore[i]) ans = vscore[i];
  ans;
  printf("%d\n", ans);
}
