#include <bits/stdc++.h>
using namespace std;
using p = pair<long long, long long>;
long long dx[4] = {-1, 0, 1, 0};
long long dy[4] = {0, 1, 0, -1};
int main() {
  long long n, u, v;
  cin >> n >> u >> v;
  vector<vector<long long>> g(n + 1);
  for (long long i = 0; i < n - 1; i++) {
    long long a, b;
    cin >> a >> b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  vector<long long> dist(n + 1, -1);
  queue<long long> que;
  que.push(v);
  dist[v] = 0;
  long long MAX = 0;
  while (!que.empty()) {
    long long v = que.front();
    que.pop();
    for (long long nv : g[v]) {
      if (dist[nv] != -1) continue;
      dist[nv] = dist[v] + 1;
      que.push(nv);
    }
  }
  vector<long long> du(n + 1, -1);
  que.push(u);
  while (!que.empty()) {
    long long v = que.front();
    que.pop();
    for (long long nv : g[v]) {
      if (dist[nv] != -1) continue;
      du[nv] = du[v] + 1;
      que.push(nv);
    }
  }
  for (long long i = 1; i <= n; i++) {
    if (dist[i] > du[i]) MAX = max(dist[i] - 1, MAX);
  }
  cout << MAX << endl;
  return 0;
}
