#include <bits/stdc++.h>
using namespace std;
long long t = 1;
const long long inf = (long long)1000000007, N = 100005;
vector<long long> dist1(N, 0), dist2(N, 0), adj[N];
void solve() {
  long long n, x, y, u, v;
  cin >> n >> u >> v;
  for (long long i = 1; i < n; i += 1) {
    cin >> x >> y;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  vector<long long> vis(N, 0);
  queue<long long> q;
  vis[u] = 1;
  dist1[u] = 0;
  q.push(u);
  while (!q.empty()) {
    long long tmp = q.front();
    q.pop();
    for (auto i : adj[tmp]) {
      if (vis[i] == 0) {
        vis[i] = 1;
        q.push(i);
        dist1[i] = dist1[tmp] + 1;
      }
    }
  }
  q.push(v);
  for (long long i = 0; i < N; i += 1) vis[i] = 0;
  vis[v] = 1;
  dist2[v] = 0;
  while (!q.empty()) {
    long long tmp = q.front();
    q.pop();
    for (auto i : adj[tmp]) {
      if (vis[i] == 0) {
        vis[i] = 1;
        q.push(i);
        dist2[i] = dist2[tmp] + 1;
      }
    }
  }
  long long res = 0;
  for (long long i = 1; i < n + 1; i += 1) {
    if (dist1[i] < dist2[i]) res = max(res, dist2[i] - 1);
  }
  cout << res << "\n";
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  while (t--) {
    solve();
  }
  return 0;
}
