from collections import deque
N, u, v = map(int, input().split())
G = {k: [] for k in range(N+1)}
for _ in range(N-1):
    a, b = map(int, input().split())
    # 無向グラフ
    G[a].append(b)
    G[b].append(a)

visited = [-1] * (N+1)

visited[v] = 0
route = []
que = deque([(v, 0)])

while que:
    ci, d = que.popleft()

    if ci == u:
        dist = d

    for ni in G[ci]:
        if visited[ni] == -1:
            visited[ni] = d+1
            que.append((ni, d+1))


que = deque([(u, 0)])
end = 0
ans = 0
while que:
    ci, p = que.popleft()

    end = 0
    que2 = deque([(ci, 0)])

    while que2:
        ci2, end_d = que2.popleft()
        end = max(end, end_d)
        for ni2 in G[ci2]:
            if visited[ni2] > visited[ci2]:
                que2.append((ni2, end_d+1))
    if ci != v:
        ans = max(ans, end+visited[ci]//2)
    # print(ci, end, visited[ci], ans)

    for ni in G[ci]:
        if visited[ni] < visited[ci]:
            que.append((ni, ci))
print(ans)
