#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<long long>>;
signed main() {
  long long N, aoki, taka;
  cin >> N >> aoki >> taka;
  Graph G(N);
  long long A, B;
  for (long long i = 0; i < N; i++) {
    cin >> A >> B;
    G.at(A - 1).push_back(B - 1);
    G.at(B - 1).push_back(A - 1);
  }
  vector<long long> Adist(N, -1);
  queue<long long> que;
  Adist.at(aoki - 1) = 0;
  que.push(aoki - 1);
  while (!que.empty()) {
    long long v = que.front();
    que.pop();
    for (long long nv : G.at(v)) {
      if (Adist.at(nv) != -1) continue;
      Adist.at(nv) = Adist.at(v) + 1;
      que.push(nv);
    }
  }
  vector<long long> Tdist(N, -1);
  Tdist.at(taka - 1) = 0;
  que.push(taka - 1);
  while (!que.empty()) {
    long long v = que.front();
    que.pop();
    for (long long nv : G.at(v)) {
      if (Tdist.at(nv) != -1) continue;
      if (Adist.at(nv) <= Tdist.at(v) + 1) continue;
      Tdist.at(nv) = Tdist.at(v) + 1;
      que.push(nv);
    }
  }
  long long ans = 0;
  for (long long i = 0; i < N; i++) {
    if (Tdist.at(i) != -1 && Adist.at(i) > ans) ans = Adist.at(i) - 1;
  }
  cout << ans << endl;
}
