#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int vis[2][N];
vector<int> v[N];
int main() {
  int n, T, A;
  scanf("%d %d %d", &n, &T, &A);
  for (int i = 1; i < n; i++) {
    int x, y;
    scanf("%d %d", &x, &y);
    v[x].push_back(y);
    v[y].push_back(x);
  }
  queue<pair<int, pair<int, int> > > q;
  q.push({0, {T, 1}});
  q.push({1, {A, 1}});
  int res = 0;
  while (!q.empty()) {
    int t = q.front().first, x = q.front().second.first,
        d = q.front().second.second;
    q.pop();
    if (vis[1][x]) {
      if (t == 0 && vis[1][x] == d - 1) {
        res = max(res, d - 1);
      }
      continue;
    }
    if (vis[0][x]) {
      if (t == 1 && vis[0][x] == d) {
        res = max(res, d);
        continue;
      }
      if (t == 0) continue;
    }
    vis[t][x] = d;
    for (auto y : v[x]) {
      q.push({t, {y, d + 1}});
    }
  }
  res--;
  for (int i = 1; i <= n; i++) {
    if ((int)v[i].size() == 1) {
      if (vis[1][i] && vis[0][i]) {
        res = max(res, vis[1][i] - 2);
      }
    }
  }
  printf("%d", res);
  return 0;
}
