#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;
struct edge {
  int to, cost;
};
int V;
vector<edge> G[100010];
ll d[100010];
void dijkstra(int s) {
  priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>> que;
  fill(d, d + V, longinf);
  d[s] = 0;
  que.push(pair<ll, ll>(0, s));
  while (!que.empty()) {
    pair<ll, ll> p = que.top();
    que.pop();
    int v = p.second;
    if (d[v] < p.first) continue;
    for (int i = (int)(0); i < (int)(G[v].size()); ++i) {
      edge e = G[v][i];
      if (d[e.to] > d[v] + e.cost) {
        d[e.to] = d[v] + e.cost;
        que.push(pair<ll, ll>(d[e.to], e.to));
      }
    }
  }
}
int main() {
  cin >> V;
  int u, v;
  cin >> u >> v;
  u--, v--;
  int a[V - 1], b[V - 1];
  for (int i = (int)(0); i < (int)(V - 1); ++i) {
    cin >> a[i] >> b[i];
    a[i]--, b[i]--;
    G[a[i]].push_back({b[i], 1});
    G[b[i]].push_back({a[i], 1});
  }
  dijkstra(v);
  int dist = (d[u] + 1) / 2;
  ll ans = 0;
  for (int i = (int)(0); i < (int)(V - 1); ++i) {
    if (d[a[i]] >= dist && d[b[i]] >= dist) {
      ans = max(ans, max(d[a[i]] - 1, d[b[i]] - 1));
    }
  }
  cout << ans << endl;
  return 0;
}
