#include <bits/stdc++.h>
using namespace std;
vector<long long int> adj[200005];
long long int st, e;
void bfs(long long int s, vector<long long int> &dist) {
  queue<long long int> q;
  q.push(s);
  dist[s] = 0;
  while (!q.empty()) {
    s = q.front();
    q.pop();
    for (long long int x : adj[s]) {
      if (dist[x] != -1 || x == st || x == e) continue;
      dist[x] = 1 + dist[s];
      q.push(x);
    }
  }
}
void solve() {
  long long int n;
  cin >> n >> st >> e;
  for (long long int i = 1; i < n; i++) {
    long long int u, v;
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  vector<long long int> a(n + 1, -1), b(n + 1, -1);
  bfs(st, a);
  bfs(e, b);
  long long int ans = 0;
  for (long long int i = 0; i <= n; i++) {
    if (a[i] != -1 && b[i] != -1 && adj[i].size() == 1 && i != st && i != e)
      ans = max(ans, min(a[i], b[i]));
  }
  cout << ans;
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int t;
  t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
