from collections import deque, Counter

N, u, v = map(int, input().split())

neighbors = [[i] for i in range(N + 1)]

for _ in range(N - 1):
    A, B = map(int, input().split())
    neighbors[A].append(B)
    neighbors[B].append(A)


def BFS(neighbors, v):
    q = deque([v])
    cost = Counter({v: 0})
    count = 0
    visited = set([v])
    while q:
        t = q.popleft()
        visited.add(t)
        count += 1
        nodes = neighbors[t][1:]
        for n in nodes:
            if n not in visited:
                cost[n] = count
                q.append(n)

    return cost

u_cost = BFS(neighbors, u)
v_cost = BFS(neighbors, v)

ans = 0
for i in range(N):
    if u_cost[i] <= v_cost[i]:
        ans = max(ans, v_cost[i])

print(ans - 1)