#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
int main() {
  i64 n, u, v;
  cin >> n >> u >> v;
  u--;
  v--;
  vector<i64> edge[n];
  for (i64 i = 0; i < n - 1; i++) {
    i64 a, b;
    cin >> a >> b;
    a--;
    b--;
    edge[a].push_back(b);
    edge[b].push_back(a);
  }
  queue<i64> que;
  vector<i64> ufar(n, 1e9), vfar(n, 1e9);
  ufar[u] = 0;
  que.push(u);
  while (que.size()) {
    i64 p = que.front();
    que.pop();
    for (i64 i : edge[p])
      if (ufar[p] + 1 < ufar[i]) {
        ufar[i] = ufar[p] + 1;
        que.push(i);
      }
    if (ufar[p] == 0) ufar[p] = 1e9;
  }
  vfar[v] = 0;
  que.push(v);
  while (que.size()) {
    i64 p = que.front();
    que.pop();
    for (i64 i : edge[p])
      if (vfar[p] + 1 < vfar[i]) {
        vfar[i] = vfar[p] + 1;
        que.push(i);
      }
  }
  i64 ans = -1;
  for (i64 i = 0; i < n; i++) {
    cerr << i << " " << ufar[i] << " " << vfar[i] << endl;
    if (ufar[i] < vfar[i]) ans = max(ans, vfar[i] - (vfar[i] - ufar[i]) % 2);
  }
  if (ans == -1)
    cout << (vfar[u] % 2 ? 0 : 1) << endl;
  else
    cout << ans << endl;
  return 0;
}
