#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> depth(n, -1);
  queue<long long> q;
  q.push(v);
  depth[v] = 0;
  while (!q.empty()) {
    auto p = q.front();
    q.pop();
    for (auto pp : to[p]) {
      if (depth[pp] != -1) continue;
      q.push(pp);
      depth[pp] = depth[p] + 1;
    }
  }
  long long res = 0;
  for (int i = 0; i < (n); ++i) {
    res = max(res, depth[i]);
  }
  if (res - 1 >= 0)
    cout << res - 1 << endl;
  else
    cout << 0 << endl;
  return 0;
}
