from collections import deque
def main():
    N, u, v = [int(i) for i in input().split()]
    u -= 1
    v -= 1
    graph = [[] for _ in range(N)]
    for i in range(N-1):
        a,b = [int(i) for i in input().split()]
        a -= 1
        b -= 1
        graph[a].append(b)
        graph[b].append(a)
    tree = [[] for _ in range(N)]
    parents = [-1] * N
    
    stack = deque([(v, -1)])
    while len(stack) > 0:
        current, parent = stack.pop()
        parents[current] = parent
        for n in graph[current]:
            if parent == n:
                continue
            stack.append((n, current))
            tree[current].append(n)
    
    current = u
    distance = 0
    while current != v:
        current = parents[current]
        distance += 1
    current = u
    cnt = 0
    res = 0
    # print(distance)
    from_n = -1
    while distance != 0:
        # print("checking %d" % current)
        stack = deque([(current, 0)])
        cnmax = 0
        # print(current)
        while len(stack) > 0:
            root, cn = stack.pop()
            cnmax = max(cn, cnmax)
            for c in tree[root]:
                if(c != from_n):
                    stack.append((c, cn+1))
            # print(cn)
        # print("---")
        res = max(res, cnmax + ((distance) // 2) + cnt)
        from_n = current
        current = parents[current]
        if current == -1:
            break
        distance -= 2
        cnt += 1
    print(res)
        
main()