def main():
    import sys

    input = sys.stdin.readline

    sys.setrecursionlimit(10 ** 7)

    def dfs(v, dist):
        for u in g[v]:
            if dist[u] == -1:
                dist[u] = dist[v] + 1
                dfs(u, dist)

    N, u, v = map(int, input().split())
    u -= 1
    v -= 1

    g = tuple(set() for _ in range(N))
    for _ in range(N - 1):
        a, b = (int(x) - 1 for x in input().split())
        g[a].add(b)
        g[b].add(a)

    dist_from_a = [-1] * N
    dist_from_a[v] = 0
    dfs(v, dist_from_a)

    def dfs2(v, d):
        ret = d
        for u in g[v]:
            if dist_from_a[u] > d + 1:
                ret = max(ret, dfs2(u, d + 1))
            elif dist_from_a[u] == d + 1:
                ret = max(ret, d + 1)
        return ret

    print(dfs2(u, 0))


if __name__ == '__main__':
    main()