#include <bits/stdc++.h>
using namespace std;
int d1[(int)1e5];
int d2[(int)1e5];
vector<vector<int>> g;
int mx = 0;
void dfs2(int v, int p, int d) {
  d2[v] = d;
  for (int u : g[v])
    if (u != p) dfs2(u, v, d + 1);
}
void dfs1(int v, int p, int d) {
  mx = max(mx, min(d2[v], d));
  if (d2[v] <= d) {
    return;
  }
  for (int u : g[v]) {
    if (u != p) dfs1(u, v, d + 1);
  }
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int u, s, t, v, n;
  cin >> n >> s >> t;
  g.resize(n);
  for (int i = 0; i < n - 1; i++) {
    cin >> u >> v;
    u--;
    v--;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  s--;
  t--;
  d1[u] = 0;
  dfs2(t, -1, 0);
  dfs1(s, -1, 0);
  cout << mx << endl;
  return 0;
}
