from typing import List

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

def dfs(v: int) -> List[int]:
    dist = [-1] * n
    dist[v] = 0
    stack = [v]
    while stack:
        now = stack.pop()
        dw = dist[now] + 1
        for ne in graph[now]:
            if dist[ne] < 0:
                continue
            dist[ne] = dw
            stack.append(ne)
    return dist

Takahashi = dfs(u-1)
Aoki = dfs(v-1)

ans = 0
for t, a in zip(Takahashi, Aoki):
    if t < a:
        ans = max(ans, a - 1)

print(ans)