#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int N, u, v;
  cin >> N >> u >> v;
  u--;
  v--;
  vector<int> tree[N];
  for (int i = 0; i < N - 1; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    tree[a].push_back(b);
    tree[b].push_back(a);
  }
  auto get_dists = [&](int f) {
    queue<pair<int, int>> qs;
    qs.push({u, 0});
    vector<int> dists(N, -1);
    auto len = -1;
    while (not qs.empty()) {
      auto q = qs.front();
      qs.pop();
      dists[q.first] = q.second;
      for (auto t : tree[q.first]) {
        if (dists[t] == -1) continue;
        qs.emplace(t, q.second + 1);
      }
    }
    return dists;
  };
  auto dfu = get_dists(u);
  auto dfv = get_dists(v);
  int ans = 0;
  for (int i = 0; i < N; i++) {
    if (tree[i].size() > 1) continue;
    if (dfu[i] < dfv[i]) {
      ans = max(ans, dfv[i] - 1);
    }
  }
  cout << ans << endl;
  return 0;
}
