import sys
input = sys.stdin.readline
from collections import deque

def solve():
  n,u,v = (int(i) for i in input().split())
  u,v = u-1,v-1
  query = [[] for _ in range(n)]
  for i in range(n-1):
    a,b = (int(i)-1 for i in input().split())
    query[a].append(b)
    query[b].append(a)
  que = deque([])
  que.append((v,str(v)))

  while que:
    #print(que)
    place,move = que.popleft()
    for i in query[place]:
      if not str(i) in move:
        que.append((i,move+str(i)))
    if len(que) == 0:
      aokiroot = move
  takahashigoal = aokiroot[-1]
  #print(takahashigoal)
  que.append((u,str(u)))
  while que:
    place,move = que.popleft()
    if str(place) == takahashigoal:
      takahashiroot = move
    else:
      for i in query[place]:
        if not str(i) in move:
          que.append((i,move+str(i)))
  ans = 0
  for i in range(min(len(takahashiroot),len(aokiroot))):
    ans += 1
    if  takahashiroot  == aokiroot:
      break

     
  print(max(0,ans-1))

solve()