from collections import deque
n,u,v=map(int,input().split())
u-=1
v-=1
g=[[] for i in range(n)]
for i in range(n-1):
    a,b=map(int,input().split())
    a-=1
    b-=1
    g[a].append(b)
    g[b].append(a)
q=deque([[u,[u]]])
x=[0]*n
x[u]=1
f=[]
while q:
    p=q.popleft()
    for i in g[p[0]]:
        if i==v:
            f=p[1]+[v]
            break
        if x[i]==0:
            x[i]=1
            q.append([i,p[1]+[i]])
    if len(f)>0:
        break
uv=f
if len(uv)%2==0:
    nu=uv[len(uv)//2-1]
    ans=len(uv)//2-1
else:
    nu=uv[len(uv)//2-1]
    ans=len(uv)//2-1
exit()
y=[0]*n
y[len(uv)//2]=1
y[nu]=1
q=deque([[nu,0]])
z=0
while q:
    p=q.popleft()
    for i in g[p[0]]:
        if y[i]==0:
            y[i]=1
            q.append([i,p[1]+1])
            z=max(z,p[1]+1)
print(ans+z)
