#F
from collections import deque
inf = float("inf")
N,u,v = map(int,input().split())
AB = [list(map(int,input().split())) for i in range(N-1)]

rcount = [0]*N
for ab in AB:
    a,b = ab
    rcount[a-1]+=1
    rcount[b-1]+=1
    
root = []
for i in range(N):
    if rcount[i] == 1:
        root.append(i+1)
        
udist = [-1]*N
udist[u-1] = 0
d = deque(AB)
while d:
    a,b = d.popleft()
    if udist[a-1] != -1:
        udist[b-1] = udist[a-1]+1
    elif udist[b-1] != -1:
        udist[a-1] = udist[b-1]+1
    else:
        d.append([a,b])
vdist = [-1]*N
vdist[v-1] = 0
d = deque(AB)
while d:
    a,b = d.popleft()
    if vdist[a-1] != -1:
        vdist[b-1] = vdist[a-1]+1
    elif vdist[b-1] != -1:
        vdist[a-1] = vdist[b-1]+1
    else:
        d.append([a,b])


        
UVdist = udist[v-1]
flag = 1
if UVdist%2 == 1:
    flag = 0
UVmove = UVdist//2
mid = -1
for i in range(N):
    if flag == 0:
        if udist[i] == UVmove and vdist[i] == UVmove+1:
            s = i+1
        if udist[i] == UVmove+1 and vdist[i] == UVmove:
            sn = i+1
    else:
        if udist[i] == UVmove-1 and vdist[i] == UVmove+1:
            s = i+1
        if udist[i] == UVmove+1 and vdist[i] == UVmove-1:
            sn = i+1
        
sdist = [-1]*N
sdist[s-1] = 0
d = deque(AB)
while d:
    a,b = d.popleft()
    if sdist[a-1] != -1:
        sdist[b-1] = sdist[a-1]+1
    elif sdist[b-1] != -1:
        sdist[a-1] = sdist[b-1]+1
    else:
        d.append([a,b])
sndist = [-1]*N
sndist[sn-1] = 0
d = deque(AB)
while d:
    a,b = d.popleft()
    if sndist[a-1] != -1:
        sndist[b-1] = sndist[a-1]+1
    elif sndist[b-1] != -1:
        sndist[a-1] = sndist[b-1]+1
    else:
        d.append([a,b])

MAX = 0
for i in range(N):
    if MAX < sdist[i]:
        if flag == 0:
            if sdist[i] <= sndist[i]:
                MAX = max(MAX,sdist[i])
        else:
            if sdist[i] <= sndist[i]:
                MAX = max(MAX,sdist[i])
    

if flag == 1:
    print(MAX+UVmove-2)
else:
    print(MAX+UVmove)

#print(s,sn)
#print(sdist,sndist)
#print(MAX,UVmove)