#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, A, T;
  cin >> n >> T >> A;
  A--;
  T--;
  deque<deque<long long int>> p(n);
  for (long long int i = 0; i < n - 1; i++) {
    long long int a, b;
    cin >> a >> b;
    a--;
    b--;
    p[a].push_back(b);
    p[b].push_back(a);
  }
  deque<long long int> da;
  deque<long long int> dt;
  deque<long long int> q;
  deque<bool> seen(n);
  seen.assign(n, false);
  seen[A] = true;
  q.push_back(A);
  da[A] = 0;
  while (!q.empty()) {
    long long int w = q.front();
    q.pop_front();
    for (long long int v : p[w]) {
      if (seen[v]) continue;
      seen[v] = true;
      q.push_back(v);
      da[v] = da[w] + 1;
    }
  }
  seen.assign(n, false);
  seen[T] = true;
  q.push_back(T);
  dt[T] = 0;
  while (!q.empty()) {
    long long int w = q.front();
    q.pop_front();
    for (long long int v : p[w]) {
      if (seen[v]) continue;
      seen[v] = true;
      q.push_back(v);
      dt[v] = dt[w] + 1;
    }
  }
  long long int m = 0;
  for (long long int i = 0; i < n; i++) {
    if (dt[i] < da[i]) m = max(da[i] - 1, m);
  }
  cout << m << "\n";
}
