#include <bits/stdc++.h>
using namespace std;
int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, U, V;
  cin >> n >> U >> V;
  vector<vector<int> > adj(n + 1);
  for (int i = 0; i < (int)(n - 1); i++) {
    int a, b;
    cin >> a >> b;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  queue<int> Q;
  vector<int> dist(n + 1, -1);
  dist[V] = 0;
  Q.push(V);
  while (Q.size()) {
    int v = Q.front();
    Q.pop();
    for (auto u : adj[v]) {
      if (dist[u] == -1) {
        dist[u] = dist[v] + 1;
        Q.push(u);
      }
    }
  }
  int ans = -1;
  for (int i = (int)(1); i <= (int)(n); i++) {
    if (adj[i].size() == 1) {
      ans = max(ans, dist[i]);
    }
  }
  ans--;
  cout << ans << endl;
  return 0;
}
