from collections import deque

n, u, v = map(int, input().split())
u -= 1
v -= 1

g = [[] for _ in range(n)]

for i in range(n-1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    g[a].append(b)
    g[b].append(a)

if u == v:
    print(0)
    exit()

memov = [-1] * n
q = deque()
memov[v] = 0
q.append((v, 0))

while q:
    v_, d = q.popleft()
    for nv in g[v_]:
        if memov[nv] != -1:
            continue
        memov[nv] = d + 1
        q.append((nv, d+1))

memou = [-1] * n
q = deque()
memou[u] = 0
q.append((u, 0))

while q:
    v_, d = q.popleft()
    for nv in g[v_]:
        if memou[nv] != -1:
            continue
        if d + 1 >= memov[nv]:
            memou[nv] = 0
            continue
        memou[nv] = d + 1
        q.append((nv, d+1))



ans = 0
max_v = -1
for i in range(n):
    if memou[i] > ans:
        ans = memou[i]
        max_v = i
diff = memov[max_v] - memou[max_v]
if diff == 0:
    print(ans)
    exit()

if diff > 2:
    ans += (diff - 2)
    diff = 1 if diff % 2 == 1 else 2
if diff == 1:
    print(ans)
    exit()
if diff == 2:
    print(ans + 1)








