#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int n, u, v;
  cin >> n >> u >> v;
  u--;
  v--;
  vector<int> adj[n];
  for (int i = 0; i < (n - 1); i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  vector<int> dist(n, 0), visited(n, 0);
  dist[u] = 0;
  queue<int> q;
  q.push(u);
  while (!q.empty()) {
    int now = q.front();
    q.pop();
    visited[now] = 1;
    for (int to : adj[now]) {
      if (visited[to]) continue;
      dist[to] = dist[now] + 1;
      q.push(to);
    }
  }
  int from = 0;
  for (int i = 1; i < n; i++) {
    if (dist[from] < dist[i]) {
      from = i;
    }
  }
  int ansu = dist[from];
  vector<int> distan(n, 0), visit(n, 0);
  distan[v] = 0;
  queue<int> que;
  que.push(v);
  while (!que.empty()) {
    int now = que.front();
    que.pop();
    visit[now] = 1;
    for (int to : adj[now]) {
      if (visit[to]) continue;
      distan[to] = distan[now] + 1;
      que.push(to);
    }
  }
  from = 0;
  for (int i = 1; i < n; i++) {
    if (distan[from] < distan[i]) {
      from = i;
    }
  }
  int ansv = distan[from];
  int ans = min(ansu, ansv);
  if (ansv == ansu) ans--;
  cout << ans << endl;
}
