#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
void print() {}
template <class H, class... T>
void print(H &&h, T &&...t) {
  cout << h << " \n"[sizeof...(t) == 0];
  print(forward<T>(t)...);
}
vector<ll> tree[100010];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N, u, v;
  cin >> N >> u >> v;
  u--;
  v--;
  for (ll i = (0); i < (N - 1); i++) {
    ll a, b;
    cin >> a >> b;
    a--;
    b--;
    tree[a].push_back(b);
    tree[b].push_back(a);
  }
  priority_queue<lpair, vector<lpair>, greater<lpair> > pq;
  ll dist[100010] = {}, dist2[100010] = {};
  for (ll i = (0); i < (N); i++) dist[i] = INF;
  dist[u] = 0;
  pq.push({0, u});
  while (!pq.empty()) {
    lpair l1 = pq.top();
    pq.pop();
    if (dist[l1.second] < l1.first) continue;
    for (auto &e : tree[l1.second]) {
      if (dist[e] > dist[l1.second] + 1) {
        dist[e] = dist[l1.second] + 1;
        pq.push(make_pair(dist[e], e));
      }
    }
  }
  for (ll i = (0); i < (N); i++) dist2[i] = INF;
  dist2[v] = 0;
  pq.push({0, v});
  while (!pq.empty()) {
    lpair l1 = pq.top();
    pq.pop();
    if (dist2[l1.second] < l1.first) continue;
    for (auto &e : tree[l1.second]) {
      if (dist2[e] > dist2[l1.second] + 1) {
        dist2[e] = dist2[l1.second] + 1;
        pq.push(make_pair(dist2[e], e));
      }
    }
  }
  ll ans = 0, diff = 0;
  for (ll i = (0); i < (N); i++) {
    if (dist[i] < dist2[i]) {
      ans = max(ans, dist[i]);
      diff = dist2[i] - dist[i];
    }
  }
  ans += diff / 2;
  print(ans);
}
