#include <bits/stdc++.h>
using namespace std;
const int MN = 1e5 + 5;
int n;
vector<int> adj[MN];
int dist[MN][2];
int pos[2];
void bfs(int first) {
  queue<int> q;
  q.push(pos[first]);
  dist[pos[first]][first] = 0;
  while (!q.empty()) {
    int cur = q.front();
    q.pop();
    for (auto &next : adj[cur])
      if (dist[next][first] == -1) {
        dist[next][first] = dist[cur][first] + 1;
        q.push(next);
      }
  }
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  cin >> n >> pos[0] >> pos[1];
  for (int i = 1; i < n; i++) {
    int u, v;
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  memset((dist), (-1), (sizeof(dist)));
  bfs(0);
  bfs(1);
  int ans = 0;
  for (int i = 1; i <= n; i++) ans = max(ans, max(dist[i][0], dist[i][1]));
  cout << ans - 1 << '\n';
}
