#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
struct edge {
  long long to, cost, val;
};
template <class T, class U>
bool chmin(T& a, const U& b) {
  if (a <= b) return false;
  a = b;
  return true;
}
template <class T, class U>
bool chmax(T& a, const U& b) {
  if (a >= b) return false;
  a = b;
  return true;
}
int T[110000], A[110000];
signed main(void) {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  for (int i = 0; i < 110000; i++) {
    T[i] = A[i] = 110000;
  }
  int N, u, v;
  cin >> N >> u >> v;
  u--;
  v--;
  vector<int> V[110000];
  for (int i = 0; i < N; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    V[a].push_back(b);
    V[b].push_back(a);
  }
  queue<int> que;
  que.push(u);
  T[u] = 0;
  while (!que.empty()) {
    int x = que.front();
    que.pop();
    for (int next : V[x]) {
      if (T[next] > T[x] + 1) {
        T[next] = T[x] + 1;
        que.push(next);
      }
    }
  }
  que.push(v);
  A[v] = 0;
  while (!que.empty()) {
    int x = que.front();
    que.pop();
    for (int next : V[x]) {
      if (A[next] > A[x] + 1) {
        A[next] = A[x] + 1;
        que.push(next);
      }
    }
  }
  int ans = 0, m;
  for (int i = 0; i < N; i++) {
    if (T[i] < A[i]) {
      if (ans < A[i]) {
        ans = A[i];
        m = i;
      }
    }
  }
  cout << A[m] - 1 << endl;
}
