#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, u, v;
  scanf("%lld %lld %lld", &n, &u, &v);
  vector<vector<long long>> link(n, vector<long long>(0));
  for (long long i = 0; i < n - 1; i++) {
    long long a, b;
    scanf("%lld %lld", &a, &b);
    link[a - 1].push_back(b - 1);
    link[b - 1].push_back(a - 1);
  }
  long long tmap[n], amap[n], used[n];
  for (long long i = 0; i < n; i++) used[i] = 0;
  queue<pair<long long, long long>> que;
  que.push({u - 1, 0});
  while (!que.empty()) {
    pair<long long, long long> apex = que.front();
    que.pop();
    used[apex.first] = 1;
    tmap[apex.first] = apex.second;
    for (long long ver : link[apex.first]) {
      if (!used[ver]) que.push({ver, apex.second + 1});
    }
  }
  for (long long i = 0; i < n; i++) used[i] = 0;
  que.push({v - 1, 0});
  while (!que.empty()) {
    pair<long long, long long> apex = que.front();
    que.pop();
    used[apex.first] = 1;
    amap[apex.first] = apex.second;
    for (long long ver : link[apex.first]) {
      if (!used[ver]) que.push({ver, apex.second + 1});
    }
  }
  long long tmp, get, ii = 1e20;
  for (long long i = 0; i < n; i++) {
    if (tmap[i] == amap[i] or tmap[i] == amap[i] + 1) {
      if (i < ii) {
        tmp = tmap[i] - (tmap[i] == amap[i] + 1);
        get = i;
        ii = i;
      }
    }
  }
  for (long long i = 0; i < n; i++) used[i] = 0;
  used[get] = 1;
  for (long long ver : link[get]) {
    if (tmap[ver] < tmap[get]) que.push({ver, tmp});
  }
  long long dist[n];
  for (long long i = 0; i < n; i++) dist[i] = -1e11;
  while (!que.empty()) {
    pair<long long, long long> apex = que.front();
    que.pop();
    used[apex.first] = 1;
    dist[apex.first] = apex.second;
    for (long long ver : link[apex.first]) {
      if (!used[ver]) que.push({ver, apex.second + 1});
    }
  }
  long long ans = 0;
  for (long long i = 0; i < n; i++) ans = max(ans, dist[i]);
  printf("%lld\n", ans);
  return 0;
}
