#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
vector<vector<ll>> g;
vector<ll> d;
ll ans = 0;
void dfs1(ll now, ll par, ll dist) {
  d[now] = dist;
  for (auto &c : g[now]) {
    if (c == par) continue;
    dfs1(c, now, dist + 1);
  }
}
void dfs2(ll now, ll par, ll dist) {
  ans = max(ans, min(d[now], dist));
  if (d[now] <= dist) return;
  for (auto &c : g[now]) {
    if (c == par) continue;
    dfs2(c, now, dist + 1);
  }
}
int main() {
  ll n, u, v;
  cin >> n >> u >> v;
  u--;
  v--;
  g.resize(n);
  d.resize(n);
  for (ll i = 0; i < n - 1; i++) {
    ll a, b;
    cin >> a >> b;
    a--;
    b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  dfs1(v, -1, 0);
  dfs2(u, -1, 0);
  cout << ans << endl;
}
