#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> tree;
void dfs(int n, int p, vector<int>& dist) {
  for (int u : tree[n]) {
    if (u == p) continue;
    dist[u] = min(dist[u], dist[n] + 1);
    dfs(u, n, dist);
  }
}
int main() {
  int N, u, v;
  cin >> N >> u >> v;
  u--;
  v--;
  tree.resize(N);
  for (int i = 0; i < N - 1; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    tree[a].push_back(b);
    tree[b].push_back(a);
  }
  vector<int> dt(N, 1e9), da(N, 1e9);
  dt[u] = 0;
  da[v] = 0;
  dfs(u, -1, dt);
  dfs(v, -1, da);
  int maxD = -1;
  int goal = -1;
  for (int i = 0; i < N; i++) {
    if (da[i] > dt[i] && da[i] - dt[i] > maxD && tree[i].size() == 1) {
      maxD = da[i] - dt[i];
      goal = i;
    }
  }
  int ans = dt[goal] + (da[goal] - dt[goal] - 1);
  cout << ans << endl;
}
