def main():
    from collections import deque
    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)

    dist_from_t = [-1] * N
    dist_from_t[u] = 0
    dfs(u, dist_from_t)

    d_to_x = dist_from_a[u] // 2
    for j in range(N):
        if (dist_from_a[j] == d_to_x and dist_from_t[j] == d_to_x) or (dist_from_a[j] - dist_from_t[j] == 1):
            x = j
            for w in g[j]:
                if dist_from_a[j] == d_to_x - 1 and dist_from_t[j] == d_to_x + 1:
                    g[j].remove(w)
                    g[w].remove(j)
                    break
            break

    dist_from_x = [-1] * N
    dist_from_x[x] = 0

    dfs(x, dist_from_x)
    d = max(dist_from_x)
    print(d + d_to_x)


if __name__ == '__main__':
    main()
