#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class U>
inline void dkstr(vector<vector<pair<int, U>>>& v, int n, int s, vector<U>& d,
                  U inf) {
  d.assign(n, inf);
  d[s] = 0;
  queue<pair<U, int>> pq;
  pq.emplace(0, s);
  while (!pq.empty()) {
    pair<U, int> p = pq.front();
    pq.pop();
    U D = p.first;
    int i = p.second;
    if (d[i] < D) continue;
    for (auto q : v[i]) {
      if (d[q.first] <= D + q.second) continue;
      d[q.first] = D + q.second;
      pq.emplace(D + q.second, q.first);
    }
  }
}
int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  istream& in(cin);
  ostream& out(cout);
  int n, u, v, a, b;
  in >> n >> u >> v;
  --u, --v;
  vector<vector<pair<int, int>>> e(n);
  for (int i = 0; i < (n - 1); ++i) {
    in >> a >> b;
    e[--a].emplace_back(--b, 1);
    e[b].emplace_back(a, 1);
  }
  vector<int> d(n), D(n);
  dkstr(e, n, u, d, INT_MAX);
  dkstr(e, n, v, D, INT_MAX);
  int ans{0}, f{}, K{};
  if ((d[0] + D[0]) % 2) {
    for (int i = 0; i < (n); ++i)
      if (d[i] < D[i]) {
        ans = max(ans, D[i] - 1);
      }
  } else {
    for (int i = 0; i < (n); ++i)
      if (d[i] < D[i]) ans = max(ans, d[i] + 1);
  }
  cout << ans << endl;
}
