#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
  return x * f;
}
int stack[20];
inline void write(int x) {
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  if (!x) {
    putchar('0');
    return;
  }
  int top = 0;
  while (x) stack[++top] = x % 10, x /= 10;
  while (top) putchar(stack[top--] + '0');
}
inline void pr1(int x) { write(x), putchar(' '); }
inline void pr2(int x) { write(x), puts(""); }
struct node {
  int x, y, next;
} a[200010];
int len, last[100010];
inline void ins(int x, int y) {
  len++;
  a[len].x = x;
  a[len].y = y;
  a[len].next = last[x];
  last[x] = len;
}
int fa[100010], f[100010], dep[100010];
inline void dfs(int x) {
  for (int k = last[x]; k; k = a[k].next) {
    int y = a[k].y;
    if (y == fa[x]) continue;
    fa[y] = x, dep[y] = dep[x] + 1;
    dfs(y);
    f[x] = max(f[x], f[y] + 1);
  }
}
int main() {
  int n = read(), p = read(), rt = read();
  for (int i = 1; i < n; i++) {
    int x = read(), y = read();
    ins(x, y), ins(y, x);
  }
  dfs(rt);
  int uf = dep[p] / 2 - 1, ans = 0, cnt = 0, ul = dep[p];
  while (cnt <= uf) {
    ans = max(ans, f[p] + ul - cnt - 1);
    cnt++, p = fa[p];
  }
  pr2(ans);
  return 0;
}
