# -*- coding: utf-8 -*-

N, ko, oni = map(int, input().split())
AB = [list(map(int, input().split())) for i in range(N-1)]

# 隣接リスト
v_edges = [[] for i in range(N+1)]

for a, b in AB:
    v_edges[a].append(b)
    v_edges[b].append(a)


oni_depth = [0]
v_depths = [-1] * (N+1)
v_onipath = [0] * (N+1)
def dfs(v_edges, v, parent, depth):
    v_depths[v] = depth

    for next_v in v_edges[v]:
        if next_v == parent:
            continue
        dfs(v_edges, v=next_v, parent=v, depth=depth+1)

    if v == oni:
        oni_depth[0] = depth
        v_onipath[v] = 1

    for c in v_edges[v]:
        if c == parent:
            continue
        v_onipath[v] += v_onipath[c]


dfs(v_edges, ko, -1, 0)  # 子, 逃げる人を根とする

#print(v_depths)
#print(v_onipath)
#print(oni_depth)

for i in range(1, N+1):
    if v_onipath[i]:
        if v_depths[i] >= (oni_depth[0] / 2):
            v_edges[i] = []


v_depths = [-1] * (N+1)
v_onipath = [0] * (N+1)
dfs(v_edges, ko, -1, 0)

print(max(v_depths))
