#include <bits/stdc++.h>
using namespace std;
void bfs(int s, vector<vector<int>> &graph, vector<int> &dis) {
  deque<int> que;
  que.push_back(s);
  dis[s] = 1;
  int cnt = 1;
  while (!que.empty()) {
    int tn = que.size();
    while (tn--) {
      auto p = que.front();
      que.pop_front();
      for (auto i : graph[p]) {
        if (dis[i]) continue;
        dis[i] = cnt;
        que.push_back(i);
      }
    }
    cnt++;
  }
  dis[s - 1] = 0;
}
int sovle() {
  int n, u, v;
  cin >> n >> u >> v;
  vector<vector<int>> graph(n);
  for (int i = 0; i < n - 1; i++) {
    int x, y;
    cin >> x >> y;
    graph[x - 1].push_back(y - 1);
    graph[y - 1].push_back(x - 1);
  }
  vector<int> dis1(n, 0);
  bfs(u - 1, graph, dis1);
  vector<int> dis2(n, 0);
  bfs(v - 1, graph, dis2);
  int res = 0;
  for (int i = 0; i < n; i++) {
    if (dis1[i] <= dis2[i]) res = max(res, dis1[i]);
  }
  return res;
}
int main() {
  int T = 1;
  while (T--) {
    int re = sovle();
    cout << re << endl;
  }
  return 0;
}
