#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 500;
const int inf = 0x3f3f3f3f;
const int p = 1e9 + 7;
int n;
int a, b;
int da[maxn], db[maxn];
vector<int> v[maxn];
void dfs1(int s, int cnt) {
  for (int i : v[s]) {
    if (da[i]) continue;
    da[s] = cnt + 1;
    dfs1(i, cnt + 1);
    da[s] = 0;
  }
  da[s] = cnt;
}
void dfs2(int s, int cnt) {
  for (int i : v[s]) {
    if (db[i]) continue;
    db[s] = cnt + 1;
    dfs2(i, cnt + 1);
    db[s] = 0;
  }
  db[s] = cnt;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> a >> b;
  for (int x, y, i = 1; i < n; i++) {
    cin >> x >> y;
    v[x].push_back(y);
    v[y].push_back(x);
  }
  dfs1(a, 0);
  dfs2(b, 0);
  int ans = 0;
  vector<int> tmp;
  for (int i = 1; i <= n; i++) {
    if (da[i] == db[i]) {
      tmp.push_back(da[i]);
    } else if (da[i] < db[i]) {
      ans = max(ans, da[i]);
    }
  }
  sort(tmp.begin(), tmp.end());
  if (tmp.size()) {
    ans = max(ans, tmp[0]);
  }
  cout << ans << endl;
  return 0;
}
