#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int INF = 1001001001;
const long long LINF = 1001002003004005006ll;
void solve() {
  int n, vT, vA;
  cin >> n >> vT >> vA;
  vT--, vA--;
  vector<vector<int> > to(n);
  for (int i = 0; i < (n - 1); i++) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  vector<int> dA(n);
  deque<pair<int, int> > q;
  vector<int> used(n);
  q.push_back(pair<int, int>(vA, 0));
  while (!q.empty()) {
    int u, d;
    tie(u, d) = q.front();
    q.pop_front();
    if (used[u]) continue;
    used[u] = 1;
    dA[u] = d;
    for (auto& v : to[u]) {
      q.push_back(pair<int, int>(v, d + 1));
    }
  };
  vector<int> dT(n, -INF);
  used.clear();
  used.resize(n, 0);
  ;
  q.push_back(pair<int, int>(vT, 0));
  while (!q.empty()) {
    int u, d;
    tie(u, d) = q.front();
    q.pop_front();
    if (used[u]) continue;
    used[u] = 1;
    if (dA[u] <= d) continue;
    dT[u] = d;
    ;
    for (auto& v : to[u]) {
      q.push_back(pair<int, int>(v, d + 1));
    }
  };
  int mx = 0;
  for (int i = 0; i < (n); i++) (mx = max(mx, dT[i]));
  int ans = 0;
  for (int i = 0; i < (n); i++) {
    if (dT[i] == mx) (ans = max(ans, dA[i] - 1));
  }
  cout << ans << endl;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  solve();
  return 0;
}
