n,v,u=map(int,input().split())
#行き先を格納
edge=[[] for _ in range(n)]
for i in range(n-1):
  a,b=map(int,input().split())
  edge[a-1].append(b-1)
  edge[b-1].append(a-1)
#print(edge)

t=0
vpast = list([v])
upast = list([u])
while 1:
  vnow = [edge[vn-1] for vn in vpast]
  V=[]
  for es in vnow:
    for e in es:
      V.append(e)
  t+=1
  for v in V:
    if v in upast:
      print(t)
      break
  #print('v-now: ', V)
  unow = [edge[un-1] for un in upast]
  U=[]
  for es in unow:
    for e in es:
      U.append(e)
  if len(U)==1:
    if U[0] in V:
      print(t)
      break
  #print('u-now: ', U)
  vpast = V
  upast = U
  #break