#%%
n, u, v = map(int, input().split())
u, v = u-1, v-1
a, b = [0] * (n-1), [0] * (n-1)
reach = [[] for _ in range(n)]
for i in range(n-1):
    a[i], b[i] = map(lambda x: int(x)-1, input().split())
    reach[a[i]].append(b[i])
    reach[b[i]].append(a[i])

##############################################################
#①aoki_route
#深さ、前のてんの情報
a_route = [[-1, -1] for _ in range(n)]
check = [0] * n
stack = [v]
check[v] = 1
a_route[v] = [-1, 0]

while len(stack) > 0:
    tmp = stack.pop(-1)
    tmp_list = reach[tmp]
    for i in tmp_list:
        if check[i] == 1:
            pass
        else:
            stack.append(i)
            check[i] = 1
            a_route[i] = [tmp, a_route[tmp][1]+1]

tmp = -1
for i in range(len(a_route)):
    if a_route[i][1] > tmp:
        tmp = a_route[i][1]
        AA = i

aoki_A = [AA]
tmp = AA
while True:
    tmp = a_route[tmp][0]
    if tmp == -1:
        break
    aoki_A.append(tmp)
"""
print('aoki')
print(a_route)
print('AA', AA)
print(aoki_A)
print('------------------')
"""

#########################################################################
#t_route
#前のてんの情報、深さ
t_route = [[-1, -1] for _ in range(n)]
check = [0] * n
stack = [u]
check[u] = 1
t_route[u] = [-1, 0]

while len(stack) > 0:
    tmp = stack.pop(-1)
    tmp_list = reach[tmp]
    for i in tmp_list:
        if check[i] == 1:
            pass
        else:
            stack.append(i)
            check[i] = 1
            t_route[i] = [tmp, t_route[tmp][1]+1]

takahashi_A = [AA]
tmp = AA
while True:
    tmp = t_route[tmp][0]
    if tmp == -1:
        break
    takahashi_A.append(tmp)
"""
print('takahashi')
print(t_route)
print(AA)
print(takahashi_A)
print('---------------')
"""

#####################################################
#3　点Cを求める
tmp = -1
CC = -1
for i in range(min(len(aoki_A), len(takahashi_A))):
    if aoki_A[i] != takahashi_A[i]:
        CC = tmp
        break
    tmp = aoki_A[i]
"""
print('CC', CC)
('----------------------------------')
"""
#####################################################
#4　AA - BB
#前のてんの情報、深さ、お高橋の点を通っているかの情報
x_route = [[-1, -1, -1] for _ in range(n)]
check = [0] * n
stack = [CC]
check[CC] = 1
x_route[CC] = [-1, 0, -1]

while len(stack) > 0:
    tmp = stack.pop(-1)
    tmp_list = reach[tmp]
    for i in tmp_list:
        if check[i] == 1:
            pass
        else:
            stack.append(i)
            check[i] = 1
            x_route[i] = [tmp, x_route[tmp][1]+1, x_route[tmp][2]]
            if i == u:
                x_route[i] = [tmp, x_route[tmp][1]+1, 1]

tmp = -1
for i in range(len(x_route)):
    if x_route[i][1] > tmp and x_route[i][2] == 1:
        tmp = x_route[i][1]
        BB = i
"""
print('CC - BB')
print(x_route)
print('BB', BB)
"""


('#######################')
dai = [AA, BB, CC]
aoki = []
takahashi = []
for i in range(3):
    aoki.append(a_route[dai[i]][1])
    takahashi.append(t_route[dai[i]][1])
"""
print(aoki)
print(takahashi)
"""
"""

if takahashi[2] < aoki[2]:
    print(aoki[0]-1)
else:
    print(max(aoki[2], aoki[1]-1))




#print(a_route)
#print(t_route)
"""
    
ans = 0
for i in range(len(a_route)):
    if t_route[i][1] < a_route[i][1]:
        ans = max(ans, a_route[i][1]-1)

print(ans)

Measured memory_bytes: 124192