import sys
n, tak, aok = map(int, input().split())
sys.setrecursionlimit(10e5)
tak = tak - 1
aok = aok - 1
neighbors = [set() for _ in range(n)]
for _ in range(n - 1):
    a, b = map(int, input().split())
    a = a - 1
    b = b - 1
    neighbors[a].add(b)
    neighbors[b].add(a)
rurality = [n] * n
def paint(rurality, here, num, output=None):
    if rurality[here] >= num:
        rurality[here] = num
        if output is not None:
            output.add(num)
        for nei in neighbors[here]:
            paint(rurality, nei, num + 1)
paint(rurality, aok, 0)
takback = tak
for _ in range((rurality[tak] - 1) // 2):
    for nei in neighbors[takback]:
        if rurality[nei] < rurality[takback]:
            takback = nei
            break
output = set()
paint(rurality, takback, rurality[takback], output)
print(max(output))