#include <bits/stdc++.h>
using namespace std;
vector<int> g[100 * 1000 + 5], tour;
int first[100 * 1000 + 5], height[100 * 1000 + 5], t = 0;
void dfs(int u, int p = -1, int h = 0) {
  first[u] = t++;
  height[u] = h;
  tour.push_back(u);
  for (int v : g[u]) {
    if (v != p) {
      dfs(v, u, h + 1);
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, mouse, cat;
  cin >> n >> mouse >> cat;
  mouse--, cat--;
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    cin >> u >> v;
    u--, v--;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  dfs(0);
  int B = 1, sz = tour.size();
  while (B < sz) {
    B *= 2;
  }
  vector<pair<int, int>> tree(2 * B);
  for (int i = 0; i < sz; i++) {
    tree[i + B] = {height[tour[i]], tour[i]};
  }
  for (int i = B - 1; i > 0; i--) {
    tree[i] = min(tree[2 * i], tree[2 * i + 1]);
  }
  auto lca = [&](int u, int v) {
    int L = first[u] + B, R = first[v] + B;
    if (L > R) swap(L, R);
    pair<int, int> ans = {1000 * 1000, -1};
    while (L <= R) {
      if (L % 2 == 1) ans = min(ans, tree[L++]);
      if (R % 2 == 0) ans = min(ans, tree[R--]);
      L /= 2, R /= 2;
    }
    return ans.second;
  };
  auto dist = [&](int u, int v) {
    return height[u] + height[v] - 2 * height[lca(u, v)];
  };
  int ans = 0;
  for (int e = 0; e < n; e++) {
    if (dist(mouse, e) < dist(cat, e)) {
      ans = max(ans, dist(cat, e) - 1);
    } else if (dist(mouse, e) == dist(cat, e)) {
      ans = max(ans, dist(cat, lca(e, mouse)));
    }
  }
  cout << ans << endl;
}
