import sys
import itertools
input = sys.stdin.readline


def read_values():
    return map(int, input().split())


def read_list():
    return list(read_values())


def read_lists(N):
    return [read_list() for n in range(N)]


def dfs(N, L, s):
    depth = [-1] * N

    stack = [(0, s)]
    while stack:
        d, p = stack.pop()
        depth[p] = d

        for q in L[p]:
            if depth[q] != -1:
                continue
            stack.append((d + 1, q))
    return depth

    
def main():
    N, u, v = read_values()
    u -= 1
    v -= 1
    L = [set() for _ in range(N)]
    for _ in range(N - 1):
        A, B = read_values()
        A -= 1
        B -= 1
        L[A].add(B)
        L[B].add(A)
    
    depth_A = dfs(N, L, v)

    res = 0
    stack = [(0, u)]
    while stack:
        d, p = stack.pop()
        if d == depth_A[p]:
            res = max(res, d)
            continue

        for q in L[p]:
            if depth_A[q] == d:
                res = max(res, d)
                continue
            
            stack.append((d + 1, q))
    
    print(res)


if __name__ == "__main__":
    main()
