def main():
    n, u, v = map(int, input().split(" "))
    if u == v:
        return 0

    graphs = {}

    for node in range(1, n+1):
        graphs[node] = []

    for i in range(n-1):
        a, b = map(int, input().split(" "))
        graphs[a].append(b)
        graphs[b].append(a)

    def calc_depth(depths, max_depths, cur_node, parent, cur_depth, cur_path):
        if cur_node == u:
            nigeru_path = cur_path
        else:
            nigeru_path = None

        depths[cur_node] = cur_depth
        childs = graphs[cur_node].copy()
        childs.remove(parent)
        
        if len(childs) == 0:
            for node in cur_path:
                max_depths[node] = max(max_depths[node], cur_depth)

        for child in childs:
            depths, max_depths, nigeru_path2 = calc_depth(depths, max_depths, child, cur_node, cur_depth+1, cur_path+[child])
            if nigeru_path2 is not None:
                nigeru_path = nigeru_path2 
        return depths, max_depths, nigeru_path

    depths = [None for i in range(n+1)]
    max_depths = [-1 for i in range(n+1)]

    cur_depth = 0
    depths[v] = cur_depth
    childs = graphs[v]
    for child in childs:
        depths, max_depths, nigeru_path2 = calc_depth(depths, max_depths, child, v, cur_depth+1, [v, child])
        if nigeru_path2 is not None:
            nigeru_path = nigeru_path2 

    nigeru_dist = len(nigeru_path) - 1
    nigeru_dist2 = nigeru_dist

    for i, node in enumerate(sorted(nigeru_path2)):
        if i == 0:
            nigeru_max_depth = max_depths[u]
        elif nigeru_dist >= 1:
            nigeru_max_depth = max(nigeru_max_depth, max_depths[node])
        nigeru_dist -= 2
        if nigeru_dist < 1:
            break

    #print(depths, nigeru_path, max_depths)

    out = max(nigeru_max_depth -1, 0)
    return out


out = main()
print(out)