#include <bits/stdc++.h>
using namespace std;
vector<int> g[100010];
int dist1[100010];
int dist2[100010];
int main(void) {
  int n, u, v;
  cin >> n >> u >> v;
  u--;
  v--;
  for (int i = 0; i < n; i++) {
    dist1[i] = 100000000;
    dist2[i] = 100000000;
  }
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  priority_queue<pair<int, long long>, vector<pair<int, long long>>,
                 greater<pair<int, long long>>>
      que;
  dist1[u] = 0;
  que.push(pair<int, long long>(u, 0));
  while (!que.empty()) {
    pair<int, long long> p = que.top();
    que.pop();
    int now = p.first;
    int cost = p.second;
    for (int i = 0; i < g[now].size(); i++) {
      int next = g[now][i];
      if (dist1[next] > cost + 1) {
        dist1[next] = cost + 1;
        que.push(pair<int, long long>(next, cost + 1));
      }
    }
  }
  dist2[v] = 0;
  que.push(pair<int, long long>(v, 0));
  while (!que.empty()) {
    pair<int, long long> p = que.top();
    que.pop();
    int now = p.first;
    int cost = p.second;
    for (int i = 0; i < g[now].size(); i++) {
      int next = g[now][i];
      if (dist2[next] > cost + 1) {
        dist2[next] = cost + 1;
        que.push(pair<int, long long>(next, cost + 1));
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (dist1[i] < dist2[i]) {
      if (dist2[i] - dist1[i] == 1)
        ans = max(ans, dist1[i]);
      else {
        if (dist2[i] - dist1[i] == 2) ans = max(ans, (dist1[i] + dist2[i]) / 2);
      }
    }
  }
  cout << ans << endl;
  return 0;
}
