#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vec = vector<ll>;
using vect = vector<double>;
using Graph = vector<vector<ll>>;
ll ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
template <typename T>
T lcm(T x, T y) {
  T z = __gcd(x, y);
  return x * y / z;
}
template <typename T>
bool primejudge(T n) {
  if (n < 2)
    return false;
  else if (n == 2)
    return true;
  else if (n % 2 == 0)
    return false;
  double sqrtn = sqrt(n);
  for (T i = 3; i < sqrtn + 1; i++) {
    if (n % i == 0) {
      return false;
    }
    i++;
  }
  return true;
}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
Graph G;
void bfs(vec &dist, ll s) {
  queue<ll> que;
  dist[s] = 0;
  que.push(s);
  while (!que.empty()) {
    ll v = que.front();
    que.pop();
    for (auto next_v : G[v]) {
      if (dist[next_v] != -1) continue;
      dist[next_v] = dist[v] + 1;
      que.push(next_v);
    }
  }
}
int main() {
  cout << fixed << setprecision(30);
  ll N;
  ll x, y;
  cin >> N >> x >> y;
  x--;
  y--;
  G.resize(N);
  for (ll i = 0; i < N; i++) {
    ll a, b;
    cin >> a >> b;
    a--;
    b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  vector<ll> distT(N, -1), distA(N, -1);
  bfs(distT, x);
  bfs(distA, y);
  ll ans = 0;
  for (ll i = 0; i < N; i++) {
    if (distT[i] <= distA[i]) ans = max(ans, distA[i] - 1);
  }
  cout << ans << endl;
  return 0;
}
