def dps(no, fno, d, hen, D, MD, P):
    D[no] = d
    P[no] = fno
    maxd = d
    for h in hen[no]:
        if h == fno:
            continue
        maxd = max(maxd, dps(h, no, d + 1, hen, D, MD, P))
    MD[no] = maxd
    return maxd


def main():
    N, u, v = map(int, input().split())
    hen = {}
    for i in range(N - 1):
        A, B = map(int, input().split())
        if A in hen.keys():
            hen[A].append(B)
        else:
            hen[A] = [B]
        if B in hen.keys():
            hen[B].append(A)
        else:
            hen[B] = [A]
    DEPTH = [-1 for i in range(N + 1)]
    MAX_DEPTH = [-1 for i in range(N + 1)]
    Parent = [-1 for i in range(N + 1)]
    dps(v, -1, 0, hen, DEPTH, MAX_DEPTH, Parent)
    ans = DEPTH[u]
    p = u
    for i in range((DEPTH[u] + 1) // 2 - 1):
        p = Parent[p]
        ans = max(ans, MAX_DEPTH[p])
    print(ans - 1)

if __name__ == '__main__':
    main()
