#include <bits/stdc++.h>
using namespace std;
int N, u, v, a, b, t[100010], ans;
vector<int> g[100010];
int main() {
  cin >> N >> u >> v;
  for (int i = 0; i < N - 1; i++) {
    cin >> a >> b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  queue<int> q;
  q.push(v);
  t[v] = 1;
  int s = 2, f = 1;
  while (!q.empty()) {
    int c = q.front();
    q.pop();
    f--;
    for (int d : g[c]) {
      if (!t[d]) {
        t[d] = s;
        q.push(d);
      }
    }
    if (!f) s++, f = q.size();
  }
  q.push(u);
  int p = 2;
  f = 1;
  while (!q.empty()) {
    int c = q.front();
    q.pop();
    f--;
    for (int d : g[c]) {
      if (p < t[d]) {
        q.push(d);
      }
      if (p == t[d] || p == t[d] + 1) ans = max(ans, t[d]);
    }
    if (!f) p++, f = q.size();
  }
  cout << ans - 1;
}
