#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using pii = pair<int, int>;
int Tlen[101010];
int Alen[101010];
int ans[101010];
vector<int> tree[101010];
int n, t, a;
queue<int> q;
bool vst[101010];
void print() {
  printf("TLEN : ");
  for (int i = 1; i <= n; i++) {
    printf("%d ", Tlen[i]);
  }
  printf("\n");
  printf("ALEN : ");
  for (int i = 1; i <= n; i++) {
    printf("%d ", Alen[i]);
  }
  printf("\n");
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> t >> a;
  for (int i = 1; i < n; i++) {
    int x, y;
    cin >> x >> y;
    tree[x].push_back(y);
    tree[y].push_back(x);
  }
  Tlen[t] = 0;
  vst[t] = 1;
  q.push(t);
  while (!q.empty()) {
    int tp = q.front();
    q.pop();
    for (auto it : tree[tp]) {
      if (!vst[it]) {
        vst[it] = 1;
        Tlen[it] = Tlen[tp] + 1;
        q.push(it);
      }
    }
  }
  Tlen[t] = 2;
  memset(vst, 0, sizeof(vst));
  Alen[a] = 0;
  vst[a] = 1;
  q.push(a);
  while (!q.empty()) {
    int tp = q.front();
    q.pop();
    for (auto it : tree[tp]) {
      if (!vst[it]) {
        vst[it] = 1;
        Alen[it] = Alen[tp] + 1;
        q.push(it);
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    if (Tlen[i] >= Alen[i]) Tlen[i] = 10000000;
  }
  memset(vst, 0, sizeof(vst));
  Tlen[t] = 0;
  vst[t] = 1;
  q.push(t);
  while (!q.empty()) {
    int tp = q.front();
    q.pop();
    for (auto it : tree[tp]) {
      if (!vst[it]) {
        vst[it] = 1;
        Tlen[it] = max(Tlen[it], Tlen[tp] + 1);
        q.push(it);
      }
    }
  }
  Tlen[t] = INT_MAX;
  for (auto it : tree[t]) {
    Tlen[t] = min(Tlen[t], Tlen[it] + 1);
  }
  int res = 0;
  for (int i = 1; i <= n; i++) {
    ans[i] = Alen[i] - 1;
    res = max(res, ans[i]);
  }
  cout << res << '\n';
}
