#include <bits/stdc++.h>
using namespace std;
const int N = 200010;
int n, s, t, tot, r;
int nex[2 * N], to[2 * N];
int head[N], ans[N], deep[N];
int read() {
  int x = 0, w = 1;
  char ch = 0;
  while (ch < '0' || ch > '9') {
    if (ch == '-') w = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + (ch - '0');
    ch = getchar();
  }
  return x * w;
}
void add(int u, int v) {
  nex[++tot] = head[u];
  head[u] = tot;
  to[tot] = v;
}
void d1(int x, int w) {
  deep[x] = deep[w] + 1;
  ans[x] = deep[x];
  for (int i = head[x]; i; i = nex[i]) {
    int v = to[i];
    if (v == w) continue;
    d1(v, x);
    ans[x] = max(ans[x], ans[v]);
  }
}
int d2(int x, int y, int w) {
  if (w >= deep[x]) return 0;
  for (int i = head[x]; i; i = nex[i]) {
    if (to[i] == w) continue;
    if (!d2(to[i], x, w + 1)) {
      r = x;
    }
  }
  return 1;
}
int main() {
  n = read();
  s = read();
  t = read();
  for (int i = 1; i <= n - 1; i++) {
    int u, v;
    u = read();
    v = read();
    add(u, v);
    add(v, u);
  }
  d1(t, 0);
  d2(s, 0, 0);
  ans[r] -= 2;
  cout << ans[r];
  return 0;
}
