import sys
sys.setrecursionlimit(10**6)
n,u,v = map(int,input().split())
l = [[] for _ in range(n+1)]
x = [0 for _ in range(n+1)]
y = [0 for _ in range(n+1)]
for i in range(n-1):
  ai,bi = map(int,input().split())
  l[ai].append(bi)
  l[bi].append(ai)
def s(p,a,m):
  global x
  for li in l[a]:
    if li != p:
      x[li] = m+1
      s(a,li,m+1)
  return
def t(p,a,m):
  global y
  for li in l[a]:
    if li != p:
      y[li] = m+1
      t(a,li,m+1)
  return
s(-1,u,0)
t(-1,v,0) 
mx = 0
for i in range(1,n+1):
  if x[i] < y[i]:
    if y[i] -1 > mx:
      mx = y[i]-1
print(mx)