#include <bits/stdc++.h>
using namespace std;
vector<long long> adj[100100];
long long vis1[100100];
long long vis2[100100];
long long dist1[100100];
long long dist2[100100];
int main() {
  long long n, u, v;
  cin >> n >> u >> v;
  long long a, b;
  for (long long i = 1; i < n; i++) {
    cin >> a >> b;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  queue<long long> q1;
  queue<long long> q2;
  q1.push(u);
  q2.push(v);
  dist1[u] = 0;
  dist2[v] = 0;
  vis1[u] = 1;
  vis2[v] = 1;
  while (!q1.empty()) {
    long long x = q1.front();
    q1.pop();
    for (long long i : adj[x]) {
      if (vis1[i] == 0) {
        dist1[i] = dist1[x] + 1;
        vis1[i] = 1;
        q1.push(i);
      }
    }
  }
  while (!q2.empty()) {
    long long x = q2.front();
    q2.pop();
    for (long long i : adj[x]) {
      if (vis2[i] == 0) {
        dist2[i] = dist2[x] + 1;
        vis2[i] = 1;
        q2.push(i);
      }
    }
  }
  long long maxi = 0;
  for (long long i = 1; i <= n; i++) {
    if (dist1[i] == dist2[i]) maxi = max(maxi, dist2[i]);
  }
  cout << maxi;
}
