#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long long inf = 5e18;
const long long N = 1e5 + 10;
long long n, u, v;
vector<set<long long>> G(N);
vector<long long> du(N, -1);
vector<long long> dv(N, -1);
int main() {
  cin >> n >> u >> v;
  u--, v--;
  for (long long i = 0; i < n - 1; i++) {
    long long a, b;
    cin >> a >> b;
    a--, b--;
    G[a].insert(b);
    G[b].insert(a);
  }
  priority_queue<pair<long long, long long>, vector<pair<long long, long long>>,
                 greater<pair<long long, long long>>>
      q;
  q.push({0, u});
  while (q.size()) {
    long long d = q.top().first;
    long long f = q.top().second;
    q.pop();
    if (du[f] > -1) continue;
    du[f] = d;
    for (long long t : G[f]) {
      if (du[t] == -1) {
        q.push({d + 1, t});
      }
    }
  }
  q.push({0, v});
  while (q.size()) {
    long long d = q.top().first;
    long long f = q.top().second;
    q.pop();
    if (dv[f] > -1) continue;
    dv[f] = d;
    for (long long t : G[f]) {
      if (dv[t] == -1) {
        q.push({d + 1, t});
      }
    }
  }
  long long id = 0;
  for (long long i = 1; i < n; i++) {
    if (dv[i] > du[i] && dv[i] > dv[id]) {
      id = i;
    }
  }
  long long ans = dv[id] - 1;
  cout << ans << endl;
}
