#include <bits/stdc++.h>
using namespace std;
void dfs(int node, int father, vector<vector<int>>& ad, vector<int>& dist) {
  dist[node] = dist[father] + 1;
  for (int nghb : ad[node])
    if (nghb != father) dfs(nghb, node, ad, dist);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, a, b;
  cin >> n >> a >> b;
  vector<vector<int>> ad(n + 1);
  for (int i = 1; i < n; i++) {
    int x, y;
    cin >> x >> y;
    ad[x].push_back(y);
    ad[y].push_back(x);
  }
  vector<int> distA(n + 1);
  dfs(a, 0, ad, distA);
  vector<int> distB(n + 1);
  dfs(b, 0, ad, distB);
  for (int i = 1; i <= n; i++)
    if (distA[b] - 1 == distA[i] + distB[i] - 2 && distA[i] == distB[i] &&
        distA[i] == 2) {
      cout << "1\n";
      return 0;
    }
  int best = 0;
  for (int i = 1; i <= n; i++)
    if (distA[i] <= distB[i] && (distB[i] - distA[i]) % 2 && ad[i].size() > 1)
      best = max(best, distB[i] - 1);
  cout << best << '\n';
  return 0;
}
