#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:16000000")
using namespace std;
const int Maxn = 100005;
int n, A, B;
vector<int> neigh[Maxn];
int distA[Maxn], distB[Maxn];
int parA[Maxn], parB[Maxn];
int best;
void Traverse(int v, int p, int lvl, int dist[], int par[]) {
  dist[v] = lvl;
  par[v] = p;
  for (int i = 0; i < neigh[v].size(); i++) {
    int u = neigh[v][i];
    if (u == p) continue;
    Traverse(u, v, lvl + 1, dist, par);
  }
}
void Solve(int v) {
  best = max(best, (distA[v] + distB[v]) / 2);
  for (int i = 0; i < neigh[v].size(); i++) {
    int u = neigh[v][i];
    if (parB[v] == u) continue;
    Solve(u);
  }
}
int main() {
  scanf("%d %d %d", &n, &A, &B);
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    scanf("%d %d", &a, &b);
    neigh[a].push_back(b);
    neigh[b].push_back(a);
  }
  Traverse(A, 0, 0, distA, parA);
  Traverse(B, 0, 0, distB, parB);
  int r = A;
  while (parB[r] && distA[parB[r]] < distB[parB[r]]) r = parB[r];
  Solve(r);
  printf("%d\n", best);
  return 0;
}
