#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;
void Main() {
  int n, u, v;
  cin >> n >> u >> v;
  u--;
  v--;
  vvi to(n);
  for (int(i) = 0; (i) < (n - 1); (i)++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  vi dist_u(n, -1);
  queue<int> q;
  q.push(u);
  dist_u[u] = 0;
  while (!q.empty()) {
    int now = q.front();
    q.pop();
    for (auto next : to[now]) {
      if (dist_u[next] == -1) {
        dist_u[next] = dist_u[now] + 1;
        q.push(next);
      }
    }
  }
  vi dist_v(n, -1);
  queue<int> emp;
  swap(q, emp);
  q.push(v);
  dist_v[v] = 0;
  while (!q.empty()) {
    int now = q.front();
    q.pop();
    for (auto next : to[now]) {
      if (dist_v[next] == -1) {
        dist_v[next] = dist_v[now] + 1;
        q.push(next);
      }
    }
  }
  int mx = -1;
  int ans = -1;
  for (int(i) = 0; (i) < (n); (i)++) {
    if (dist_u[i] >= dist_v[i]) continue;
    if (dist_u[i] > mx) {
      mx = dist_u[i];
      ans = dist_v[i];
    }
  }
  cout << ans - 1 << endl;
  return;
}
int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
  return 0;
}
