n, u, v = list(map(int, input().split(' ')))
paths = {}
for i in range(n-1):
    a, b = list(map(int, input().split(' ')))
    paths[a] = paths.get(a, []) + [b]
    paths[b] = paths.get(b, []) + [a]
# 鬼を root にした時に逃げる人が途中で鬼に追いつかれずにたどり着ける葉までの root からの深さが答えっぽい(+-1位ズレそうだけど)
# print(paths)
u_leaves = {}
v_leaves = {}
def f(current, parent, cost, uv):
    finish = True
    for vertex in paths[current]:
        if vertex == parent:
            continue
        f(vertex, current, cost + 1, uv)
        finish = False
    if finish:
        if uv == 'u':
            u_leaves[current] = cost
        else:
            v_leaves[current] = cost
f(u, None, 0, 'u')
f(v, None, 0, 'v')
# print(u_leaves)
# print(v_leaves)
ans = 0
for i in range(1, n+1):
    if i in u_leaves and i in v_leaves:
        ans = max(ans, max(v_leaves[i], u_leaves[i]) - 1)  # ???
        if u_leaves[i] == v_leaves.get(i, 0):
            ans = 1
print(ans)