#include <bits/stdc++.h>
using namespace std;
vector<int> Tree[100001];
int memo[100001];
bool visited[100001];
int main() {
  int n, u, v;
  cin >> n >> u >> v;
  for (int i = 1; i < n; i++) {
    int a, b;
    cin >> a >> b;
    Tree[a].push_back(b);
    Tree[b].push_back(a);
  }
  memo[v] = 0;
  visited[v] = true;
  stack<int> s;
  s.push(v);
  while (s.empty() == false) {
    int now = s.top();
    s.pop();
    for (int next : Tree[now]) {
      if (visited[next]) continue;
      visited[next] = true;
      memo[next] = memo[now] + 1;
      s.push(next);
    }
  }
  for (int i = 1; i <= n; i++) visited[i] = false;
  int time = 0, ans = 0;
  s.push(u);
  while (s.empty() == false) {
    int now = s.top();
    s.pop();
    visited[now] = true;
    if (time > memo[now])
      continue;
    else {
      ans = max(ans, memo[now] - 1);
    }
    ++time;
    for (int next : Tree[now]) {
      if (visited[next]) continue;
      s.push(next);
    }
  }
  cout << ans << endl;
  return 0;
}
