#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, u, v;
  cin >> n >> u >> v;
  u--;
  v--;
  vector<vector<int>> a(n);
  for (int i = 0; i < (int)(n - 1); i++) {
    int tmpa, tmpb;
    cin >> tmpa >> tmpb;
    tmpa--;
    tmpb--;
    a[tmpa].push_back(tmpb);
    a[tmpb].push_back(tmpa);
  }
  vector<pair<int, int>> score(n);
  vector<bool> isSearch1(n, false), isSearch2(n, false);
  queue<int> q;
  q.push(u);
  score[u].first = 0;
  isSearch1[u] = true;
  while (!q.empty()) {
    int x = q.front();
    isSearch1[x] = true;
    q.pop();
    for (auto l : a[x]) {
      if (isSearch1[l] == true) continue;
      q.push(l);
      score[l].first = score[x].first + 1;
    }
  }
  q.push(v);
  score[v].second = 0;
  isSearch2[v] = true;
  while (!q.empty()) {
    int x = q.back();
    isSearch2[x] = true;
    q.pop();
    for (auto l : a[x]) {
      if (isSearch2[l] == true) continue;
      q.push(l);
      score[l].second = score[x].second + 1;
    }
  }
  int ans = 0;
  for (int i = 0; i < (int)(n); i++) {
    if (score[i].first < score[i].second) {
      ans = max(ans, score[i].second);
    }
  }
  cout << max(ans - 1, 0) << endl;
}
