#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpll = vector<pll>;
int ctoi(char c) {
  switch (c) {
    case '0':
      return 0;
    case '1':
      return 1;
    case '2':
      return 2;
    case '3':
      return 3;
    case '4':
      return 4;
    case '5':
      return 5;
    case '6':
      return 6;
    case '7':
      return 7;
    case '8':
      return 8;
    case '9':
      return 9;
    default:
      return 0;
  }
}
bool pairCompare(const pll firstElof, pll secondElof) {
  return firstElof.first > secondElof.first;
}
ll nod(ll F) { return log10(F) + 1; }
ll i, j, k, l, m, n;
ll N, M, K, H, W, L;
string S;
ll MOD = 1000000007;
ll ans = 0;
ll INF = 9999999999999;
vl flag, color;
vll path;
vl A, T;
void bfs(ll now) {
  queue<ll> Q;
  Q.push(now);
  ll u;
  while (!Q.empty()) {
    u = Q.front();
    Q.pop();
    flag[u] = 1;
    ll v;
    for (ll i = 0; i < path[u].size(); i++) {
      v = path[u][i];
      if (flag[v] == 0) {
        A[v] = A[u] + 1;
        Q.push(v);
      }
    }
  }
}
void bfs2(ll now) {
  queue<ll> Q;
  Q.push(now);
  ll u;
  while (!Q.empty()) {
    u = Q.front();
    Q.pop();
    flag[u] = 1;
    ll v;
    for (ll i = 0; i < path[u].size(); i++) {
      v = path[u][i];
      if (flag[v] == 0) {
        T[v] = T[u] + 1;
        Q.push(v);
      }
    }
  }
}
int main() {
  cin >> N;
  flag.resize(N);
  path.resize(N);
  A.resize(N);
  T.resize(N);
  ll U, V;
  cin >> U >> V;
  for (i = 0; i < N - 1; i++) {
    ll a, b;
    cin >> a >> b;
    path[a - 1].push_back(b - 1);
    path[b - 1].push_back(a - 1);
  }
  A[V - 1] = 0;
  bfs(V - 1);
  for (i = 0; i < N; i++) {
    flag[i] = 0;
  }
  T[U - 1] = 0;
  bfs2(U - 1);
  vl C(N);
  for (i = 0; i < N; i++) {
    C[i] = 0;
  }
  for (i = 0; i < N; i++) {
    if (T[i] < A[i]) {
      C[T[i]] = 2;
    } else if (T[i] == A[i]) {
      C[T[i]] = 1;
    }
  }
  for (i = 0; i < N; i++) {
    if (C[i] == 0) {
      cout << i - 1;
      exit(0);
    } else if (C[i] == 1) {
      cout << i;
      exit(0);
    }
  }
}
