#include <bits/stdc++.h>
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;
}
using ll = long long;
using ull = unsigned long long;
using namespace std;
const ll INF = 100100100;
int main() {
  ll n;
  cin >> n;
  ll u, v;
  cin >> u >> v;
  u--;
  v--;
  vector<vector<ll>> G(n);
  for (int i = 0; i < (n - 1); i++) {
    ll a, b;
    cin >> a >> b;
    a--;
    b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  vector<ll> da(n, INF), db(n, INF);
  da[v] = 0;
  queue<ll> que1;
  que1.push(v);
  while (!que1.empty()) {
    ll p = que1.front();
    que1.pop();
    for (auto nv : G[p]) {
      if (da[nv] <= da[p] + 1) continue;
      da[nv] = da[p] + 1;
      que1.push(nv);
    }
  }
  db[u] = 0;
  queue<ll> que2;
  que2.push(u);
  while (!que2.empty()) {
    ll p = que2.front();
    que2.pop();
    for (auto nv : G[p]) {
      if (db[nv] <= db[p] + 1) continue;
      db[nv] = db[p] + 1;
      que2.push(nv);
    }
  }
  if (G[v].size() == 1 && G[v][0] == u) {
    cout << 0 << endl;
    return 0;
  }
  ll ans = 0;
  for (int i = 0; i < (n); i++) {
    if (da[i] < db[i]) {
      if (db[i] > ans) ans = db[i];
    }
  }
  cout << ans << endl;
}
