import sys
input = sys.stdin.readline
n,u,v=map(int, input().split())
u-=1
v-=1
es=[[] for i in range(n)]
for i in range(n-1):
    a0,b0=map(int, input().split())
    es[a0-1].append(b0-1)
    es[b0-1].append(a0-1)
aoki=[-1]*n
aoki[v]=0
choku=[-1]*n
choku[u]=0
from collections import deque
que=deque([])
que.append(u)
while que:
    now=que.popleft()
    step=choku[now]
    for e in es[now]:
        if choku[e]==-1:
            choku[e]=step+1
            que.append(e)

que=deque([])
que.append(v)
while que:
    now=que.popleft()
    step=aoki[now]
    for e in es[now]:
        if aoki[e]==-1:
            aoki[e]=step+1
            que.append(e)

end=None

for i in range(n):
    if len(es[i])==1: 
        if choku[i]==0:
            continue
        if end==None and aoki[i]-choku[i]>0:
            end=(aoki[i]-choku[i],aoki[i],choku[i])
        elif aoki[i]-choku[i]>0:
            if end[0]==aoki[i]-choku[i] and aoki[i]>end[1]:
                end=(aoki[i]-choku[i],aoki[i],choku[i])
            elif end[0]>aoki[i]-choku[i]:
                end=(aoki[i]-choku[i],aoki[i],choku[i])

if end!=None:
    print(max(end[2]-(end[0]-1), aoki[u]-1))
else:
    print(aoki[u]-1)