#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
int n, k, ans = 0;
int ec = 0, to[800005], nxt[800005], hed[400005] = {0};
void add_edge(int f, int t) {
  ++ec;
  to[ec] = t;
  nxt[ec] = hed[f];
  hed[f] = ec;
}
int dsv[400005] = {0}, fa[400005] = {0};
int dsu[400005] = {0};
int lis[400005], lcn = 0;
void dfs1(int u, int f) {
  dsv[u] = dsv[f] + 1;
  fa[u] = f;
  for (int i = hed[u]; i; i = nxt[i]) {
    int v = to[i];
    if (v == f) continue;
    dfs1(v, u);
  }
}
void dfs2(int u, int f) {
  dsu[u] = dsu[f] + 1;
  for (int i = hed[u]; i; i = nxt[i]) {
    int v = to[i];
    if (v == f) continue;
    dfs2(v, u);
  }
}
int main() {
  int u, v, a, b;
  cin >> n >> u >> v;
  for (int i = 1; i < n; i++) {
    cin >> a >> b;
    add_edge(a, b);
    add_edge(b, a);
  }
  dfs1(v, 0);
  while (u != v) {
    lis[++lcn] = u;
    u = fa[u];
  }
  lis[++lcn] = u;
  int vv = lis[lcn >> 1];
  int ffa = fa[vv];
  dfs2(vv, ffa);
  for (int i = 1; i <= n; i++) ans = max(ans, dsv[i]);
  cout << ans - 2 << endl;
  return 0;
}
