import sys
from collections import deque
input = sys.stdin.readline

N , u,v = map(int,input().split())
u -= 1
v -= 1
lis = [[int(i)-1 for i in input().split()]for _ in range(N-1)]
adj = [[] for i in range(N)]
for (i,j) in lis:
    adj[i].append(j)
    adj[j].append(i)
l = [[v,0,False]]
q = deque(l)
b = [-1]*N
b[v] = 0
ans = 0
m = 0
for _ in range(N-1):
    i, n ,bl = q.popleft()
    for j in adj[i]:
        if j == u:
            ans = n+1
            bl = True
        if bl:
            m = n
        if b[j]==-1:
            q.append([j,n+1,bl])
            b[j] = n+1

i,n,bl = q.popleft()
l = [i]
mal = [-1]*(n+1)
mal[-1] = i
nn = n
for _ in range(nn):
    for j in adj[i]:
        if nn-1 == b[j]:
            i = j
            mal[nn-1] = j
            nn -= 1
            break

nu = ans
uu = u
bln = False
for _ in range(nu):
    for j in adj[uu]:
        if nu-1 == b[j]:
            uu = j
            nu -= 1
            if mal[nu] == uu:
                bln = True
                break
    if bln:
        break


if nu > ans - nu or bl:
    print(n-1)
else:
    print(m-1)
