N, u, v = map(int, input().split())
graph = [[] for _ in range(N+1)]

for _ in range(N-1):
  a, b = map(int, input().split())
  graph[a].append(b)
  graph[b].append(a)

A = [-1] * (N + 1)
T = [-1] * (N + 1)

stack = [u]
T[u] = 0
while stack:
  s = stack.pop()
  for g in graph[s]:
    if T[g] == -1:
      T[g] = T[s] + 1
      stack.append(g)
#print("T:", T)

stack = [v]
A[v] = 0
while stack:
  s = stack.pop()
  for g in graph[s]:
    if A[g] == -1:
      A[g] = A[s] + 1
      stack.append(g)
#print("A:", A)

answer = []
for i in range(N+1):
  if A[i] > T[i]:
    answer.append(T[i] + (A[i] - T[i]) // 2)
print(max(answer))