#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using VL = vector<ll>;
const long long INF = 999999999;
ll N, u, v;
ll du[100010], dv[100010];
ll deep[100010];
ll w;
vector<ll> e[100010];
bool used[100010];
void dfs_u(ll s, ll dis) {
  used[s] = true;
  du[s] = dis;
  for (int i = 0; i < e[s].size(); i++) {
    if (!used[e[s][i]]) {
      dfs_u(e[s][i], dis + 1);
    }
  }
  return;
}
void dfs_v(ll s, ll dis, ll bound) {
  used[s] = true;
  if (bound >= dis) {
    w = max(w, deep[s]);
  } else {
    return;
  }
  for (int i = 0; i < e[s].size(); i++) {
    if (!used[e[s][i]]) {
      dfs_v(e[s][i], dis + 1, bound);
    }
  }
  return;
}
ll deepen(ll s) {
  bool flag = false;
  used[s] = true;
  for (int i = 0; i < e[s].size(); i++) {
    if (!used[e[s][i]]) {
      flag = true;
      return deep[s] = max(deep[s], deepen(e[s][i]));
    }
  }
  if (!flag) return deep[s] = du[s];
}
int main() {
  cin >> N;
  cin >> u >> v;
  du[u] = 0;
  dv[v] = 0;
  for (int i = 0; i < N - 1; i++) {
    ll s, t;
    cin >> s >> t;
    e[s].push_back(t);
    e[t].push_back(s);
  }
  fill(used, used + N, false);
  dfs_u(u, 0);
  fill(used, used + N, false);
  int d = du[v];
  if (d == 1)
    cout << 0 << endl;
  else {
    deepen(u);
    w = deep[v];
    fill(used, used + N, false);
    dfs_v(v, 0, (d - 2) / 2);
    if (dv[u] % 2 == 1) {
      cout << w << endl;
    } else if (dv[u] % 2 == 0) {
      cout << w - 1 << endl;
    }
  }
}
