n,g,s = map(int,input().split())
G = [[] for _ in range(n)]
for i in range(n-1):
  a,b = map(int,input().split())
  G[a-1].append(b-1)
  G[b-1].append(a-1)
  
def dfs(v,d):
  if vs[v] != -1:
    return
  vs[v] = d
  for nv in G[v]:
    dfs(nv,d+1)

def dfs2(v,d):
  if vg[v] != -1:
    return
  vg[v] = d
  if d >= vs[v]:
    return  
  for nv in G[v]:
    dfs2(nv,d+1)
  
vs = [-1]*n
vg = [-1]*n

dfs(s-1,0)
dfs2(g-1,0)

print(max(vg))