n,u,v=map(int,input().split())
ab=[list(map(int,input().split())) for i in range(n-1)]
data=[[] for i in range(n+1)]
for a,b in ab:
    data[a].append(b)
    data[b].append(a)
flag=[-1]*(n+1)
que=[u]
flag[u]=0
cnt=1
while que:
    h=[]
    for x in que:
        for y in data[x]:
            if flag[y]==-1:
                flag[y]=cnt
                h.append(y)
    cnt+=1
    que=h
flag_2=[-1]*(n+1)
que=[v]
flag_2[v]=0
cnt=1
start=0
ans=0
if flag[v]<=2:
    start=v
else:
    while que:
        h=[]
        for x in que:
            for y in data[x]:
                if flag_2[y]==-1:
                    flag_2[y]=cnt
                    h.append(y)
                    if flag[y]-flag_2[y]<=2:
                        ans=flag_2[y]
                        start=y
                        break
            else:
                continue
            break
        else:
            cnt+=1
            que=h
            continue
        break
que=[start]
while que:
    ans+=1
    h=[]
    for x in que:
        for y in data[x]:
            if flag_2[y]==-1:
                flag_2[y]=ans
                h.append(y)
    que=h
print(ans-2)