#include <bits/stdc++.h>
using namespace std;
long long n, u, v;
vector<vector<long long>> to;
vector<bool> seen, haji;
long long ans = 0;
void dfs(long long cv) {
  if (to[cv].size() == 1) {
    haji[cv] = true;
  }
  for (auto&(nv) : (to[cv])) {
    if (seen[nv]) continue;
    if (nv == v) continue;
    seen[nv] = true;
    dfs(nv);
  }
}
void calcDist(long long cv, long long d) {
  if (haji[cv]) {
    ans = max(ans, d - 1);
    return;
  }
  for (auto&(nv) : (to[cv])) {
    if (seen[nv]) continue;
    seen[nv] = true;
    calcDist(nv, d + 1);
  }
}
int main() {
  cin >> n >> u >> v;
  u--;
  v--;
  to = vector<vector<long long>>(n);
  seen = vector<bool>(n, false);
  for (long long i = 0; i < n - 1; i++) {
    long long a, b;
    cin >> a >> b;
    a--;
    b--;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  haji = vector<bool>(n, false);
  dfs(u);
  seen = vector<bool>(n, false);
  calcDist(v, 0);
  cout << ans << endl;
}
