#include <bits/stdc++.h>
using namespace std;
const long long INF = 1145141919;
const long long MOD = 1000000007;
template <class T>
void chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
  }
}
template <class T>
void chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
  }
}
long long N, u, v;
vector<long long> path[101010];
long long U[101010], V[101010], parent[101010];
long long V2[101010];
long long ha[101010];
void dep() {
  for (long long(i) = 1; (i) <= (N); (i)++) U[i] = INF;
  for (long long(i) = 1; (i) <= (N); (i)++) V[i] = INF;
  for (long long(i) = 1; (i) <= (N); (i)++) parent[i] = -1;
  queue<long long> Q;
  priority_queue<pair<long long, long long> > PQ;
  U[u] = 0;
  Q.push(u);
  for (; !Q.empty(); Q.pop()) {
    long long idx = Q.front();
    for (long long(i) = 0; (i) < (path[idx].size()); (i)++) {
      long long to = path[idx][i];
      if (U[to] < INF) continue;
      U[to] = U[idx] + 1;
      Q.push(to);
    }
  }
  V[v] = 0;
  Q.push(v);
  for (; !Q.empty(); Q.pop()) {
    long long idx = Q.front();
    long long flg = 1;
    for (long long(i) = 0; (i) < (path[idx].size()); (i)++) {
      long long to = path[idx][i];
      if (V[to] < INF) continue;
      V[to] = V[idx] + 1;
      Q.push(to);
      parent[to] = idx;
      flg = 0;
    }
    if (flg) {
      PQ.push(pair<long long, long long>(V[idx], idx));
      ha[idx] = 1;
    }
  }
  for (; !PQ.empty();) {
    long long d = PQ.top().first;
    long long idx = PQ.top().second;
    PQ.pop();
    if (V2[idx]) continue;
    V2[idx] = d;
    long long to = parent[idx];
    if (to < 0) continue;
    if (V2[to]) continue;
    if (V[to] > V[idx]) continue;
    PQ.push(pair<long long, long long>(V2[idx], to));
  }
}
int main() {
  cin >> N >> u >> v;
  for (long long(i) = 1; (i) <= (N - 1); (i)++) {
    long long a, b;
    cin >> a >> b;
    path[a].push_back(b);
    path[b].push_back(a);
  }
  dep();
  long long cnt = 0;
  long long idx = u;
  for (;;) {
    long long p = parent[idx];
    if (ha[idx] && V[p] <= cnt) break;
    if (ha[idx] && V[p] <= cnt + 1) {
      cnt++;
      break;
    }
    if (ha[idx]) {
      idx = p;
      cnt++;
      continue;
    }
    if (V[p] > cnt + 1) {
      idx = p;
      cnt++;
      continue;
    }
    long long tmp = -1;
    for (long long(i) = 0; (i) < (path[idx].size()); (i)++) {
      long long to = path[idx][i];
      if (V2[to] == V2[idx]) tmp = to;
    }
    idx = tmp;
    cnt++;
  }
  cout << cnt << endl;
  return 0;
}
