#include <bits/stdc++.h>
using namespace std;
int checku[100001];
int checkv[100001];
vector<int> adj[100001];
int historyu[100001];
int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, u, v;
  memset(checkv, -1, sizeof(checkv));
  memset(checku, -1, sizeof(checku));
  memset(historyu, -1, sizeof(historyu));
  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);
  }
  checku[u] = 0;
  queue<int> que;
  que.push(u);
  while (!que.empty()) {
    int now = que.front();
    que.pop();
    for (auto next : adj[now]) {
      if (checku[next] == -1) {
        checku[next] = checku[now] + 1;
        que.push(next);
      }
    }
  }
  checkv[v] = 0;
  que.push(v);
  while (!que.empty()) {
    int now = que.front();
    que.pop();
    for (auto next : adj[now]) {
      if (checkv[next] == -1) {
        checkv[next] = checkv[now] + 1;
        que.push(next);
      }
    }
  }
  int res = 1e9;
  int Max = 0;
  for (int i = 1; i <= n; i++) {
    Max = max(Max, checkv[i]);
  }
  for (int i = 1; i <= n; i++) {
    if (checku[i] == checkv[i]) {
      res = min(res, checkv[i]);
    }
    if (checkv[i] == Max) {
      res = min(res, checkv[i] - 1);
    }
  }
  cout << res << '\n';
  return 0;
}
