#include <bits/stdc++.h>
using namespace std;
long long n, u, v, a, b, d1[100009], d2[100009];
vector<long long> e[100009];
int main() {
  cin >> n >> u >> v;
  for (long long i = (long long)0; i < (long long)n - 1; i++) {
    cin >> a >> b;
    e[a].push_back(b);
    e[b].push_back(a);
  }
  queue<long long> que;
  que.push(v);
  for (long long i = (long long)0; i < (long long)n + 1; i++)
    d1[i] = d2[i] = 1e18;
  d1[v] = 0;
  while (!que.empty()) {
    long long x = que.front();
    que.pop();
    for (long long i = (long long)0; i < (long long)e[x].size(); i++) {
      if (d1[e[x][i]] == 1e18) {
        d1[e[x][i]] = d1[x] + 1;
        que.push(e[x][i]);
      }
    }
  }
  d2[u] = 0;
  que.push(u);
  while (!que.empty()) {
    long long x = que.front();
    que.pop();
    if (d1[x] == d2[x]) continue;
    for (long long i = (long long)0; i < (long long)e[x].size(); i++) {
      if (d2[e[x][i]] == 1e18) {
        d2[e[x][i]] = d2[x] + 1;
        que.push(e[x][i]);
      }
    }
  }
  long long mn = 1e18, mx = 0;
  for (long long i = (long long)1; i < (long long)n + 1; i++) {
    if (d1[i] == d2[i]) {
      mn = d1[i];
    }
    if (d1[i] > d2[i]) {
      mx = max(mx, d1[i] - 1);
    }
  }
  cout << min(mx, mn) << endl;
}
