#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, u, v;
  cin >> n >> u >> v;
  vector<vector<int>> t(n);
  for (int i = 0; i < n - 1; ++i) {
    int a, b;
    cin >> a >> b;
    t[a - 1].push_back(b - 1);
    t[b - 1].push_back(a - 1);
  }
  vector<int> du(n, 100000000);
  du[u - 1] = 0;
  queue<int> qu;
  qu.push(u - 1);
  while (!qu.empty()) {
    int tmp = qu.front();
    qu.pop();
    for (int i : t[tmp]) {
      if (du[i] > du[tmp] + 1) {
        du[i] = du[tmp] + 1;
        qu.push(i);
      }
    }
  }
  vector<int> dv(n, 100000000);
  dv[v - 1] = 0;
  queue<int> qv;
  qv.push(v - 1);
  while (!qv.empty()) {
    int tmp = qv.front();
    qv.pop();
    for (int i : t[tmp]) {
      if (dv[i] > dv[tmp]) {
        dv[i] = dv[tmp] + 1;
        qv.push(i);
      }
    }
  }
  int r = 0;
  for (int i = 0; i < n; ++i) {
    if (du[i] > dv[i])
      continue;
    else
      r = max(r, du[i] - 1);
  }
  cout << r << endl;
}
