#include <bits/stdc++.h>
using namespace std;
long long n, t, a, hoge[100000], huga[100000], ans;
vector<long long> v[100000];
void kr(long long s, long long memo[100000]) {
  bool visited[100000] = {};
  priority_queue<pair<long long, long long>, vector<pair<long long, long long>>,
                 greater<pair<long long, long long>>>
      pq;
  pq.push(make_pair(0, s));
  while (pq.size()) {
    long long cost = pq.top().first, to = pq.top().second;
    pq.pop();
    if (visited[to]) continue;
    visited[to] = true;
    memo[to] = cost;
    for (auto i : v[to]) pq.push(make_pair(cost + 1, i));
  }
}
signed main() {
  cin >> n >> t >> a;
  --t, --a;
  for (long long i = 0; i < (long long)(n - 1); ++i) {
    long long c, d;
    cin >> c >> d;
    --c, --d;
    v[c].push_back(d);
    v[d].push_back(c);
  }
  kr(t, huga);
  kr(a, hoge);
  for (long long i = 0; i < (long long)(n); ++i)
    if (huga[i] < hoge[i]) ans = max(ans, huga[i] + (hoge[i] - huga[i]) / 2);
  cout << ans << endl;
}
