#include <bits/stdc++.h>
using namespace std;
int n, u, v, ans;
vector<int> adj[100001];
int dist[100001];
int dist2[100001];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> u >> v;
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  memset(dist, -1, sizeof(dist));
  memset(dist2, -1, sizeof(dist2));
  queue<pair<int, bool> > q;
  q.push(make_pair(u, false));
  q.push(make_pair(v, true));
  dist2[u] = 0;
  dist[v] = 0;
  while (!q.empty()) {
    int cur = q.front().first;
    int upd = q.front().second;
    q.pop();
    for (auto i : adj[cur]) {
      if (upd) {
        if (dist[i] != -1) continue;
        dist[i] = dist[cur] + 1;
        q.push(make_pair(i, true));
      } else {
        if (dist2[i] != -1) continue;
        dist2[i] = dist2[cur] + 1;
        q.push(make_pair(i, false));
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    if (dist[i] == dist2[i] - 1) {
      ans = max(ans, dist[i]);
    } else if (dist[i] == dist2[i]) {
      if (ans == 0) ans = dist[i];
      ans = min(ans, dist[i]);
    } else if (dist[i] > dist2[i]) {
      if (dist[i] % 2 != dist2[i] % 2) {
        ans = max(ans, dist2[i]);
      } else {
        continue;
        ans = max(ans, dist[i]);
      }
    }
  }
  cout << ans;
}
