#include <bits/stdc++.h>
using namespace std;
int n, i, u, v, par[100005], dis[100005] = {0}, far[100005] = {0};
vector<int> g[100005];
bool used[100005] = {0};
void dfs(int x) {
  used[x] = true;
  dis[x] = dis[par[x]] + 1;
  for (i = 0; i < g[x].size(); i++) {
    if (!used[g[x][i]]) {
      par[g[x][i]] = x;
      dfs(g[x][i]);
    }
  }
  far[par[x]] = max(far[par[x]], dis[x]);
}
int main() {
  int a, b, d = 0, dk = 0, e, p, ans = 0, memo = 0, pb, mp, ff, ss;
  cin >> n >> u >> v;
  for (i = 1; i < n; i++) {
    cin >> a >> b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  par[v] = 0;
  dis[0] = -1;
  dfs(v);
  for (i = 1; i <= n; i++)
    if (far[i] == 0) far[i] = dis[i];
  p = u;
  dk = dis[u];
  while (1) {
    mp = 0;
    pb = dk;
    memo++;
    p = par[p];
    mp = memo;
    if (pb % 2 == 0)
      ss = pb / 2;
    else
      ss = (pb - 1) / 2;
    if (pb <= 2 * memo) {
      ans = max(ans, ss);
      break;
    }
    pb = pb - 2 * memo;
    ff = far[p] - dis[p];
    mp += ff;
    if (pb % 2 == 0)
      ss = pb - 1;
    else
      ss = pb - 1;
    mp += (2 * ss - 1);
    ans = max(ans, mp);
  }
  cout << ans << endl;
  return 0;
}
