#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
vector<int> adj[N];
int n, rob, pol;
int police[N], robbery[N];
void bfs(int start, int *dis) {
  queue<int> q;
  dis[start] = 0;
  q.push(start);
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (int nxt : adj[u]) {
      if (dis[nxt] == -1) {
        dis[nxt] = dis[u] + 1;
        q.push(nxt);
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int a, b;
  cin >> n >> rob >> pol;
  for (int i = 1; i < n; i++) {
    cin >> a >> b;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  memset(police, -1, sizeof police);
  memset(robbery, -1, sizeof robbery);
  bfs(rob, robbery);
  bfs(pol, police);
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    if (robbery[i] < police[i]) {
      ans = max(ans, police[i] - 1);
    } else if (robbery[i] == police[i]) {
      ans = max(ans, robbery[i]);
    }
  }
  cout << ans << '\n';
  return 0;
}
