#include <bits/stdc++.h>
using namespace std;
vector<vector<long long int> > G =
    vector<vector<long long int> >(100001, vector<long long int>(0, 0));
vector<long long int> toa(100001), tob(100001), ans(100001, 0);
void dfs(long long int now, long long int from, long long int d,
         long long int mode) {
  (mode == 0 ? toa[now] : tob[now]) = d;
  for (int i = 0; i < G[now].size(); i++) {
    if (G[now][i] == from) continue;
    dfs(G[now][i], now, d + 1, mode);
  }
}
void check(long long int now, long long int from) {
  if (toa[now] > tob[now]) return;
  if (toa[now] == tob[now]) {
    ans[now] = toa[now];
    return;
  }
  ans[now] = toa[now] - 1;
  for (int i = 0; i < G[now].size(); i++) {
    if (G[now][i] == from) continue;
    check(G[now][i], now);
  }
}
int main(int argc, char const *argv[]) {
  long long int x, y, n, a, b;
  std::cin >> n >> a >> b;
  for (long long int i = 0; i < n - 1; i++) {
    std::cin >> x >> y;
    G[x].push_back(y);
    G[y].push_back(x);
  }
  dfs(a, -1, 0, 0);
  dfs(b, -1, 0, 1);
  check(a, -1);
  long long int t = 0;
  for (int i = 1; i <= n; i++) t = max(t, ans[i]);
  std::cout << t << '\n';
  return 0;
}
