#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, u, v;
  cin >> n >> u >> v;
  --u;
  --v;
  vector<vector<long long>> to(n);
  for (int i = 0; i < (n); ++i) {
    int a, b;
    cin >> a >> b;
    --a;
    --b;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  vector<long long> daoki(n, -1);
  queue<long long> q;
  q.push(v);
  daoki[v] = 0;
  while (!q.empty()) {
    auto p = q.front();
    q.pop();
    for (auto pp : to[p]) {
      if (daoki[pp] != -1) continue;
      q.push(pp);
      daoki[pp] = daoki[p] + 1;
    }
  }
  vector<long long> dtakahashi(n, -1);
  q.push(u);
  dtakahashi[u] = 0;
  while (!q.empty()) {
    auto p = q.front();
    q.pop();
    for (auto pp : to[p]) {
      if (dtakahashi[pp] != -1) continue;
      q.push(pp);
      dtakahashi[pp] = dtakahashi[p] + 1;
    }
  }
  long long res = 0;
  for (int i = 0; i < (n); ++i) {
    if (dtakahashi[i] < daoki[i]) {
      res = max(res, daoki[i] - 1);
    }
  }
  cout << max(res, 0ll) << endl;
  return 0;
}
