import sys
sys.setrecursionlimit(10**6)
n,u,v=map(int,input().split())
l=[[] for i in range(n+1)]
for i in range(n-1):
  a,b=map(int,input().split())
  l[a].append(b)
  l[b].append(a)
d1=[-1 for i in range(n+1)]
def dfs(num,now):
  d1[num]=now
  dic=l[num]
  for i in dic:
    if d1[i]!=-1:
      pass
    else:
      dfs(i,now+1)
dfs(u,0)
d2=[-1 for i in range(n+1)]
def dfs1(num,now):
  d2[num]=now
  dic=l[num]
  for i in dic:
    if d2[i]!=-1:
      pass
    else:
      dfs1(i,now+1)
dfs1(v,0)
ans=0
for i in range(1,n+1):
  if d2[i]>=d1[i]:
    pass
  else:
    if d2[i]%2!=d1[i]%2:
      ans1=d1[i]
    else:
      ans1=d1[i]
    ans=max(ans,ans1)
print(ans)