#include <bits/stdc++.h>
using namespace std;
using UI = unsigned int;
using UL = unsigned long;
using LL = long long;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int, int>;
using VP = vector<PII>;
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
int dfs(VVI &es, VI &d, VI &par, int i, int cnt = 0) {
  d[i] = cnt;
  int mv = 1;
  for (const int &dst : es[i]) {
    if (dst == par[i]) continue;
    par[dst] = i;
    mv = max(mv, dfs(es, d, par, dst, cnt + 1));
  }
  return 0;
}
int getd(VVI &es, VI &d, VI &par, int i) {
  int ret = d[i];
  for (const int &dst : es[i]) {
    if (dst == par[i]) continue;
    ret = max(ret, getd(es, d, par, dst));
  }
  return ret;
}
void solve() {
  int n, u, v;
  cin >> n >> u >> v;
  --u;
  --v;
  VVI es(n);
  int a, b;
  for (int i = int(0); i < int(n - 1); i++) {
    cin >> a >> b;
    --a;
    --b;
    es[a].push_back(b);
    es[b].push_back(a);
  }
  VI par(n, -1), d(n);
  dfs(es, d, par, u);
  int pp = v;
  while (par[pp] != u) pp = par[pp];
  int ans = d[v] - 1;
  for (const int &dst : es[u]) {
    if (dst == pp) continue;
    int gd = getd(es, d, par, dst);
    ans = max(ans, gd + d[pp] - 1);
  }
  int td = (d[v] - 1) / 2 + 1;
  int t = v;
  while (d[t] != td) t = par[t];
  for (const int &dst : es[par[t]]) {
    if (dst == par[par[t]]) continue;
    if (dst == t) continue;
    int gd = getd(es, d, par, dst);
    ans = max(ans, gd + d[v] - d[par[t]] * 2 - 1);
  }
  cout << ans << endl;
}
signed main() {
  solve();
  return 0;
}
