#include <bits/stdc++.h>
using namespace std;
vector<int> G[100100];
int main() {
  int n;
  int t, a;
  cin >> n >> t >> a;
  for (int i = 0; i < (int)(n - 1); i++) {
    int x, y;
    cin >> x >> y;
    G[x].push_back(y);
    G[y].push_back(x);
  }
  vector<int> dp(n + 10, 1e9);
  queue<pair<int, int> > que;
  que.push(pair<int, int>(a, 0));
  dp[a] = 0;
  while (!que.empty()) {
    pair<int, int> p = que.front();
    que.pop();
    for (auto i : G[p.first]) {
      if (dp[i] > p.second + 1) {
        que.push(pair<int, int>(i, p.second + 1));
        dp[i] = p.second + 1;
      }
    }
  }
  que.push(pair<int, int>(t, 0));
  vector<int> dpt(n + 10, 1e9);
  dpt[t] = 0;
  int ans = 0;
  while (!que.empty()) {
    pair<int, int> p = que.front();
    que.pop();
    for (auto i : G[p.first]) {
      if (dp[i] <= p.second + 1) {
        if (dp[i] % 2 != (p.second + 1) % 2) {
          ans = max(ans, min(p.second, dp[i]));
        } else {
          ans = max(ans, min(p.second + 1, dp[i]));
        }
      } else if (dpt[i] > p.second + 1) {
        que.push(pair<int, int>(i, p.second + 1));
        dpt[i] = p.second + 1;
        if (dp[i] % 2 != dpt[i] % 2) {
          ans = max(ans, min(dpt[i] - 1, dp[i]));
        } else {
          ans = max(ans, min(dpt[i], dp[i]));
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
