from collections import defaultdict


def visit(to, visited, depth, dic):
    if to in visited:
        return
    visited.add(to)
    dic[to] = depth
    available_edge = edges[to]
    for e in available_edge:
        visit(e, visited, depth + 1, dic)


def walk(to, visited):
    if to in visited:
        return
    visited.add(to)
    if depths_runner[to] < depths_tracer[to]:
        valid.add(depths_tracer[to])
        available_edges = edges[to]
        for e in available_edges:
            walk(e, visited)


num_vertex, tracer, runner = map(int, input().split())

edges = defaultdict(set)
for _ in range(1, num_vertex):
    src, dest = map(int, input().split())
    edges[src].add(dest)
    edges[dest].add(src)

if runner in edges[tracer]:
    print(0)
    exit(0)

# print(edges)
depths_tracer = defaultdict(set)
visit(tracer, set(), 0, depths_tracer)
# print(depths_tracer)

depths_runner = defaultdict(set)
visit(runner, set(), 0, depths_runner)
# print(depths_runner)

valid = set()
walk(runner, set())
ans = max(valid)

if ans % 2 == 0:
    ans -= 1

print(ans)
exit(0)
