#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000000;
int main() {
  int n;
  cin >> n;
  int u, v;
  cin >> u >> v;
  u--;
  v--;
  vector<int> to[100005];
  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> dist1(n, INF);
  vector<int> dist2(n, INF);
  queue<int> que1;
  queue<int> que2;
  dist1[u] = 0;
  que1.push(u);
  while (!que1.empty()) {
    int t = que1.front();
    que1.pop();
    for (auto next : to[t]) {
      if (dist1[next] != INF) continue;
      dist1[next] = dist1[t] + 1;
      que1.push(next);
    }
  }
  dist2[v] = 0;
  que2.push(v);
  while (!que2.empty()) {
    int t = que2.front();
    que2.pop();
    for (auto next : to[t]) {
      if (dist2[next] != INF) continue;
      dist2[next] = dist2[t] + 1;
      que2.push(next);
    }
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (dist1[i] < dist2[i]) {
      ans = max(ans, dist1[i]);
    }
  }
  cout << ans << endl;
  return 0;
}
