n,u,v=map(int,input().split())
E=[[] for _ in range(n+1)]
for _ in range(n-1):
    a,b=map(int,input().split())
    E[a].append(b)
    E[b].append(a)
depth=[-1]*(n+1)
height=[-1]*(n+1)
def dsf_1(p,d):
    depth[p]=d
    for c in E[p]:
        if depth[c]==-1:
            dsf_1(c,d+1)
dsf_1(v,0)
def dsf_2(p):
    if len(E[p])==1 and p!=v:
        height[p]=0
    else:
        h=0
        for c in E[p]:
            if height[c]==-1 and depth[c]>depth[p]:
                dsf_2(c)
            h=max(h,height[c])
        h+=1
        height[p]=h
dsf_2(v)
d=depth[u]
dd=d//2+1
while d>dd:
    for c in E[u]:
        if depth[c]==d-1:
            u=c
            d-=1
            break
print(height[u]+depth[u]-1)