n,u,v=map(int,input().split())
u=u-1
v=v-1
edge=[]
for i in range(n-1):
    a,b=map(int,input().split())
    edge.append((a-1,b-1))
dp1=[-1]*n
dp1[u]=0
dp2=[-1]*n
dp2[v]=0

root=[[] for i in range(n)]
for a,b in edge:
    root[a].append(b)
    root[b].append(a)

def dfs(node,depth,par,dp):
    for vertex in root[node]:
        if vertex == par:
            continue
        dp[vertex]=depth+1
        dfs(vertex,depth+1,node,dp)
dfs(u,0,u,dp1)
dfs(v,0,v,dp2)
buf=-1
buf1=0
#print(dp1,dp2,root)
for i in range(n):
    if dp1[i]<dp2[i] and dp2[i]>buf:
        buf=dp2[i]
        buf1=dp1[i]
print(buf-1)