#include <bits/stdc++.h>
using namespace std;
template <class T>
bool chmax(T& a, const T& b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T& a, const T& b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
const long long INF = 1LL << 60;
long long gcd(long long a, long long b) {
  if (b == 0) {
    return a;
  } else {
    return gcd(b, a % b);
  }
}
int main() {
  long long u, v, n;
  cin >> n >> u >> v;
  vector<vector<long long>> E(n);
  vector<long long> T(n, INF);
  vector<long long> A(n, INF);
  T[u - 1] = 0;
  A[v - 1] = 0;
  for (int i = 0; i < (int)(n); i++) {
    long long a, b;
    cin >> a >> b;
    E[a - 1].push_back(b - 1);
    E[b - 1].push_back(a - 1);
  }
  queue<pair<long long, pair<long long, long long>>> que;
  que.push(make_pair(0LL, make_pair(u - 1LL, -1LL)));
  while (!que.empty()) {
    auto q = que.front();
    que.pop();
    long long dis = q.first;
    long long now = q.second.first;
    long long old = q.second.second;
    if (T[now] < dis) continue;
    T[now] = dis;
    for (int i = 0; i < (int)(E[now].size()); i++) {
      if (old != E[now][i]) {
        que.push({dis++, {E[now][i], now}});
      }
    }
  }
  que.push(make_pair(0LL, make_pair(v - 1LL, -1LL)));
  while (!que.empty()) {
    auto q = que.front();
    que.pop();
    long long dis = q.first;
    long long now = q.second.first;
    long long old = q.second.second;
    if (A[now] < dis) continue;
    A[now] = dis;
    for (int i = 0; i < (int)(E[now].size()); i++) {
      if (old != E[now][i]) {
        que.push({dis + 1, {E[now][i], now}});
      }
    }
  }
  long long ans = 0;
  for (int i = 0; i < (int)(n); i++) {
    if (T[i] < A[i]) {
      chmax(ans, A[i]);
    }
  }
  cout << ans - 1 << endl;
}
