#include <bits/stdc++.h>
using namespace std;
int dist[100005];
int arrived[100005];
int leaf[100005];
vector<int> G[100005];
int dfs(int idx, int d) {
  arrived[idx] = 1;
  dist[idx] = d;
  int f = 1;
  for (int i = 0; i < G[idx].size(); i++) {
    int j = G[idx][i];
    if (arrived[j]) continue;
    f = 0;
    dfs(j, d + 1);
  }
  leaf[idx] = f;
}
int dist2[100005];
int arrived2[100005];
int INF = 1 << 20;
int dfs2(int idx, int d) {
  arrived2[idx] = 1;
  if (d >= dist[idx]) d = INF;
  dist2[idx] = d;
  for (int i = 0; i < G[idx].size(); i++) {
    int j = G[idx][i];
    if (arrived2[j]) continue;
    dfs(j, d + 1);
  }
}
int main() {
  ios::sync_with_stdio(false);
  int N, U, V, A, B;
  cin >> N >> U >> V;
  for (int i = 0; i < N - 1; i++) {
    cin >> A >> B;
    G[A].push_back(B);
    G[B].push_back(A);
  }
  dfs(V, 0);
  dfs2(U, 0);
  int ret = 0;
  for (int i = 1; i <= N; i++) {
    if (dist2[i] >= INF) continue;
    if (!leaf[i]) continue;
    int d = dist[i] - 1;
    ret = max(ret, d);
  }
  cout << ret << endl;
}
