def f(s):
  d=[-1]*-~n
  d[s]=0
  q=[s]
  while q:
    v=q.pop()
    c=d[v]+1
    for w in e[v]:
      if d[w]<0:
        d[w]=c
        q+=w,
  return d
n,u,v,*t=map(int,open(0).read().split())
e=[[]for _ in range(n+1)]
for a,b in zip(*[iter(t)]*2):
  e[a]+=b,
  e[b]+=a,
m=0
for a,b in zip(*map(f,(u,v))):
  if a<b:m=max(m,b-1)
print(m)