#include <bits/stdc++.h>
using namespace std;
long long mo = 1000000007;
template <class T, class S>
void cmin(T &a, const S &b) {
  if (a > b) a = b;
}
template <class T, class S>
void cmax(T &a, const S &b) {
  if (a < b) a = b;
}
template <class A>
void PR(A a, long long n) {
  for (int i = 0; i < n; i++) {
    if (i) cout << ' ';
    cout << a[i];
  }
  cout << "\n";
}
long double PI = 3.14159265358979323846;
int main() {
  long long N, u, v;
  cin >> N >> u >> v;
  u--;
  v--;
  vector<long long> A(N - 1), B(N - 1);
  vector<vector<long long>> G(N);
  for (int i = 0; i < N - 1; i++) {
    cin >> A[i] >> B[i];
    A[i]--;
    B[i]--;
    G[A[i]].push_back(B[i]);
    G[B[i]].push_back(A[i]);
  }
  queue<long long> que;
  vector<long long> du(N, 1e18), dv(N, 1e18);
  que.push(u);
  du[u] = 0;
  while (!que.empty()) {
    long long a = que.front();
    que.pop();
    for (auto &b : G[a]) {
      if (du[b] != 1e18) continue;
      du[b] = du[a] + 1;
      que.push(b);
    }
  }
  que.push(v);
  dv[v] = 0;
  while (!que.empty()) {
    long long a = que.front();
    que.pop();
    for (auto &b : G[a]) {
      if (dv[b] != 1e18) continue;
      dv[b] = dv[a] + 1;
      que.push(b);
    }
  }
  long long dis = du[v];
  long long M = 0;
  long long id = -1;
  for (int i = 0; i < N; i++) {
    if (dv[i] - du[i] > 0) {
      if (M <= du[i]) {
        M = du[i];
        id = i;
      }
    }
  }
  long long ans = M + (dv[id] - du[id] - 1);
  cout << ans << endl;
}
