#include <bits/stdc++.h>
using namespace std;
struct edge {
  long long to, cost;
};
vector<edge> g[200001];
long long d1[200001], d2[200001], d3[200001];
long long r1 = -1, r2 = -1;
void dijkstra1(int s) {
  priority_queue<pair<long long, long long>,
                 vector<pair<long long, long long> >,
                 greater<pair<long long, long long> > >
      que;
  fill(d1, d1 + 200001, 10000000000000);
  d1[s] = 0;
  que.push(pair<long long, long long>(0, s));
  while (!que.empty()) {
    pair<long long, long long> p = que.top();
    que.pop();
    int v = p.second;
    if (d1[v] < p.first) continue;
    for (int i = 0; i < g[v].size(); i++) {
      edge e = g[v][i];
      if (d1[e.to] > d1[v] + e.cost) {
        d1[e.to] = d1[v] + e.cost;
        que.push(pair<long long, long long>(d1[e.to], e.to));
      }
    }
  }
}
void dijkstra2(int s) {
  priority_queue<pair<long long, long long>,
                 vector<pair<long long, long long> >,
                 greater<pair<long long, long long> > >
      que;
  fill(d2, d2 + 200001, 10000000000000);
  d2[s] = 0;
  que.push(pair<long long, long long>(0, s));
  while (!que.empty()) {
    pair<long long, long long> p = que.top();
    que.pop();
    int v = p.second;
    if (d2[v] < p.first) continue;
    for (int i = 0; i < g[v].size(); i++) {
      edge e = g[v][i];
      if (d2[e.to] > d2[v] + e.cost) {
        d2[e.to] = d2[v] + e.cost;
        que.push(pair<long long, long long>(d2[e.to], e.to));
      }
    }
  }
}
void dijkstra3(int s) {
  priority_queue<pair<long long, long long>,
                 vector<pair<long long, long long> >,
                 greater<pair<long long, long long> > >
      que;
  fill(d3, d3 + 200001, 10000000000000);
  d3[s] = 0;
  que.push(pair<long long, long long>(0, s));
  while (!que.empty()) {
    pair<long long, long long> p = que.top();
    que.pop();
    int v = p.second;
    if (d3[v] < p.first) continue;
    for (int i = 0; i < g[v].size(); i++) {
      edge e = g[v][i];
      if (e.to == r2) continue;
      if (d3[e.to] > d3[v] + e.cost) {
        d3[e.to] = d3[v] + e.cost;
        que.push(pair<long long, long long>(d3[e.to], e.to));
      }
    }
  }
}
int main() {
  long long U;
  long long N;
  long long V;
  scanf("%lld", &N);
  vector<long long> A((N - 1) - 1 + 1);
  vector<long long> B((N - 1) - 1 + 1);
  scanf("%lld", &U);
  scanf("%lld", &V);
  U--;
  V--;
  for (int i = 0; i <= (N - 1) - 1; i++) {
    scanf("%lld", &A[i]);
    scanf("%lld", &B[i]);
    A[i]--;
    B[i]--;
    edge e1 = {B[i], 1};
    g[A[i]].push_back(e1);
    edge e2 = {A[i], 1};
    g[B[i]].push_back(e2);
  }
  dijkstra1(U);
  dijkstra2(V);
  for (long long i = 0; i < N; i++) {
    if (d1[i] == (d1[V] - 1) / 2 && d2[i] == (d1[V] + 2) / 2) r1 = i;
  }
  for (long long i = 0; i < N; i++) {
    if (d1[i] == (d1[V] + 1) / 2 && d2[i] == (d1[V]) / 2) r2 = i;
  }
  if (d1[V] == 1) {
    cout << "0" << endl;
    return 0;
  }
  if (d1[V] == 2) {
    cout << "1" << endl;
    return 0;
  }
  dijkstra3(r1);
  long long l = -1;
  for (long long i = 0; i < N; i++) {
    if (d3[i] != 10000000000000) l = max(l, d3[i]);
  }
  cout << (d1[V] - 1) / 2 + l << endl;
  return 0;
}
