from collections import*
n,u,v=map(int,input().split())
e=[[]for _ in range(n+1)]
INF=10**18
d=[INF]*(n+1)
for _ in range(n-1):
  a,b=map(int,input().split())
  e[a]+=[b]
  e[b]+=[a]
q=deque([v])
d[v]=0
while q:
  now=q.popleft()
  for to in e[now]:
    if d[to]!=INF:continue
    d[to]=d[now]+1
    q.append(to)
q=[(u,0)]
ans=0
while q:
  now,c=q.pop()
  for to in e[now]:
    if d[to]>c+1:q+=[(to,c+1)]
    elif d[to]==c+1:ans=max(c+1,ans)
    else:ans=max(c,ans)
print(ans)