#include <bits/stdc++.h>
using namespace std;
int main() {
  long n, u, v;
  cin >> n >> u >> v;
  u--;
  v--;
  vector<long> edge[n];
  long a, b;
  for (int i = 0; i < n - 1; i++) {
    cin >> a >> b;
    a--;
    b--;
    edge[a].push_back(b);
    edge[b].push_back(a);
  }
  long par[n];
  par[v] = -1;
  queue<long> que;
  que.push(v);
  bool visited[n];
  fill_n(visited, n, true);
  long rank[n];
  rank[v] = 0;
  vector<int> happa;
  bool fl;
  while (!que.empty()) {
    long now = que.front();
    que.pop();
    visited[now] = false;
    fl = true;
    for (int i = 0; i < edge[now].size(); i++) {
      int to = edge[now][i];
      if (visited[to]) {
        que.push(to);
        rank[to] = rank[now] + 1;
        par[to] = now;
        fl = false;
      }
    }
    if (fl) happa.push_back(now);
  }
  queue<long> gyaku;
  long maxdeep[n];
  fill_n(maxdeep, n, 0);
  fill_n(visited, n, true);
  for (int i = 0; i < happa.size(); i++) {
    gyaku.push(happa[i]);
    maxdeep[happa[i]] = rank[happa[i]];
  }
  while (!que.empty()) {
    long now = gyaku.front();
    gyaku.pop();
    visited[now] = false;
    maxdeep[par[now]] = max(maxdeep[par[now]], maxdeep[now]);
    if (visited[par[now]]) {
      gyaku.push(par[now]);
    }
  }
  long nowrank = rank[u];
  long cango = nowrank - ((nowrank - 1) / 2);
  long ans = -1;
  for (int i = 0; i < n; i++) {
    if (rank[i] > cango) {
      ans = max(ans, maxdeep[i] - 1);
    }
  }
  ans = max(ans, maxdeep[u] - 1);
  cout << ans << endl;
}
