#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, u, v;
  cin >> n >> u >> v;
  vector<vector<long long> > G(n);
  long long a, b;
  for (long long i = 0; i < n - 1; i++) {
    cin >> a >> b;
    G[a - 1].push_back(b - 1);
    G[b - 1].push_back(a - 1);
  }
  queue<long long> q;
  long long *du = new long long[n];
  for (long long i = 0; i < n; i++) du[i] = -1;
  du[u - 1] = 0;
  bool *check = new bool[n];
  check[v - 1] = true;
  q.push(u - 1);
  while (!q.empty()) {
    long long x = q.front();
    for (long long i = 0; i < G[x].size(); i++) {
      long long p = G[x][i];
      if (du[p] >= 0) continue;
      du[p] = du[x] + 1;
      q.push(p);
    }
    q.pop();
  }
  long long *dv = new long long[n];
  for (long long i = 0; i < n; i++) dv[i] = -1;
  dv[v - 1] = 0;
  check[v - 1] = true;
  q.push(v - 1);
  while (!q.empty()) {
    long long x = q.front();
    for (long long i = 0; i < G[x].size(); i++) {
      long long p = G[x][i];
      if (dv[p] >= 0) continue;
      dv[p] = dv[x] + 1;
      q.push(p);
    }
    q.pop();
  }
  long long g = u - 1;
  for (long long i = 0; i < n; i++) {
    if (G[i].size() == 1 && du[i] <= dv[i] && du[i] > du[g]) g = i;
  }
  cout << dv[g] - 1 << endl;
  return 0;
}
