n,u,v=map(int,input().split())
u-=1
v-=1
d=[[]for _ in range(n)]
inf=float('inf')
aoki=[inf]*n
for i in range(n-1):
  a,b=map(int,input().split())
  a-=1
  b-=1
  d[a].append(b)
  d[b].append(a)
Q=d[v]
aoki[v]=0
dis=1
visited={v}
while Q:
  P=[]
  for i in Q:
    visited.add(i)
    for j in d[i]:
      if j not in visited:P.append(j)
    aoki[i]=dis
  dis+=1
  Q=P
chokudai=[-1]*n
chokudai[u]=0
dis=1
cant=set()
Q=d[u]
while Q:
  P=[]
  visited=set()
  for i in Q:
    if i in cant:
      continue
    if dis>=aoki[i]:
      if dis==aoki[i]:chokudai[i]=dis
      cant.add(i)
      continue
    else:
      chokudai[i]=dis
    for j in d[i]:
      if j not in visited:
        P.append(j)
        visited.add(j)
  dis+=1
  Q=P
#ans=0
#for i in range(n):
#  if chokudai[i]!=-1:ans=max(ans,chokudai[i])
#print(ans)
print(max(chokudai))