n, u, v = map(int, input().split())
edges = {}
for i in range(n-1):
  a, b = map(int, input().split())
  if a in edges.keys():
    edges[a].append(b)
  else:
    edges[a] = [b]
  if b in edges.keys():
    edges[b].append(a)
  else:
    edges[b] = [a]

tkhs = [-1 for i in range(n+1)]
def search1(node, t):
  tkhs[node] = t
  t += 1
  for edge in edges[node]:
    if tkhs[edge] == -1 and edge != v:
      search1(edge, t)
    elif edge == v:
      tkhs[edge] = t
aok = [-1 for i in range(n+1)]
def search2(node, t):
  aok[node] = t
  t += 1
  for edge in edges[node]:
    if aok[edge] == -1:
      search2(edge, t)
search1(u, 0)
search2(v, 0)

ans = 0
for i in range(1, n+1):
  if tkhs[i] < aok[i] and tkhs[i] != -1:
    ans = max(ans, aok[i] - 1)
print(ans)