#include <bits/stdc++.h>
using namespace std;
const long long INF = 1LL << 60;
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
long long modpow(long long a, long long n, long long mod) {
  long long res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}
int dist_A[100100] = {0};
int dist_T[100100] = {0};
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, u, v;
  cin >> N >> u >> v;
  u--;
  v--;
  vector<vector<int>> G(N);
  int A, B;
  for (int i = 0; i < N - 1; i++) {
    cin >> A >> B;
    A--;
    B--;
    G[A].push_back(B);
    G[B].push_back(A);
  }
  for (int i = 0; i < N; i++) {
    dist_A[i] = -1;
    dist_T[i] = -1;
  }
  dist_T[u] = 0;
  queue<int> que;
  que.push(u);
  while (!que.empty()) {
    int tv = que.front();
    que.pop();
    for (int nv : G[tv]) {
      if (dist_T[nv] != -1) continue;
      dist_T[nv] = dist_T[tv] + 1;
      que.push(nv);
    }
  }
  dist_A[v] = 0;
  queue<int> queA;
  queA.push(v);
  while (!queA.empty()) {
    int tu = queA.front();
    queA.pop();
    for (int nv : G[tu]) {
      if (dist_A[nv] != -1) continue;
      dist_A[nv] = dist_A[tu] + 1;
      queA.push(nv);
    }
  }
  queue<int> qn;
  qn.push(u);
  int ans = 0;
  vector<bool> visit(N);
  for (int i = 0; i < N; i++) {
    visit[i] = false;
  }
  while (!qn.empty()) {
    int now = qn.front();
    visit[now] = true;
    qn.pop();
    for (int nv : G[now]) {
      if (visit[nv]) continue;
      if (dist_T[nv] < dist_A[nv]) {
        chmax(ans, dist_A[nv]);
        qn.push(nv);
      }
    }
  }
  if (G[u].size() == 1 && G[u][0] == v) {
    cout << 0 << endl;
  } else if (ans == 0) {
    cout << 1 << endl;
  } else {
    cout << ans - 1 << endl;
  }
  return 0;
}
