#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
const ll INF = 1LL << 32;
void bfs(vvll& es, vll& d, ll s) {
  queue<ll> q;
  q.push(s);
  d[s] = 0;
  while (!q.empty()) {
    ll u = q.front();
    q.pop();
    for (auto v : es[u]) {
      if (d[v] == -1) {
        q.push(v);
        d[v] = d[u] + 1;
      }
    }
  }
}
int main() {
  ll n, u, v;
  cin >> n >> u >> v;
  u--;
  v--;
  vvll es(n);
  vll dt(n, -1);
  vll da(n, -1);
  for (ll i = 0; i < n - 1; i++) {
    ll x, y;
    cin >> x >> y;
    x--;
    y--;
    es[x].push_back(y);
    es[y].push_back(x);
  }
  bfs(es, dt, u);
  bfs(es, da, v);
  ll tnige = -1;
  ll tmax = 0;
  for (ll i = 0; i < n; i++) {
    if (dt[i] <= da[i]) {
      tnige = i;
      tmax = max(tmax, da[i]);
    }
  }
  assert(tnige != -1);
  cout << da[tnige] - 1 << endl;
  return 0;
}
