import sys
sys.setrecursionlimit(10*5)

N,u,v=map(int,input().split())

du,dv=[0]*-~N,[0]*-~N
T=[list() for i in range(-~N)]

def dsf(p,t,v,d):
  d[v]=t
  for i in T[v]:
    if i!=p:
      dsf(v,t+1,i,d)

for i in range(N-1):
  a,b=map(int,input().split())
  T[a].append(b)
  T[b].append(a)

dsf(0,0,u,du)
dsf(0,0,v,dv)

if du[v]==1 and len(T[v])==1:
  print(0)
else:
  m=0
  for i in range(1,~-N):
    if du[i] < dv[i]:
      if m<du[i]:
        v,m=i,du[i]

  if m!=0:
    print(du[v]+(m if m%2 else m-1))
  else:
    m=N+1
    for i in range(1,~-N):
      if du[i]==dv[i]:
        m=min(m,du[i])
    print(m)
