#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
int diss[100000 + 10], dist[100000 + 10];
vector<int> each[100000 + 10];
void dfs1(int now, int prev, int dis) {
  diss[now] = dis;
  for (auto it : each[now]) {
    if (it != prev) dfs1(it, now, dis + 1);
  }
}
void dfs2(int now, int prev, int dis) {
  dist[now] = dis;
  for (auto it : each[now]) {
    if (it != prev) dfs2(it, now, dis + 1);
  }
}
int dis3[100000 + 10], res = 0;
void dfs3(int now, int prev, int dis) {
  if (diss[now] > dist[now]) return;
  res = max(diss[now], res);
  if (diss[now] == dist[now]) {
    return;
  }
  for (auto it : each[now]) {
    if (it != prev) dfs3(it, now, -1);
  }
}
int main() {
  int n, s, t;
  cin >> n >> s >> t;
  for (int i = 1; i <= n; ++i) diss[i] = dist[i] = dis3[i] = INF;
  for (int i = 1; i <= n - 1; ++i) {
    int u, v;
    scanf("%d %d", &u, &v);
    each[u].push_back(v);
    each[v].push_back(u);
  }
  dfs1(s, -1, 0);
  dfs2(t, -1, 0);
  dfs3(s, -1, 0);
  cout << res << endl;
  return 0;
}
