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)

    q = deque()
    q.append((u, -1, 0))

    while q:
        t, p, cost = q.popleft()
        for next_t in g[t]:
            if next_t == p:
                continue
            if dist_from_a[next_t] > cost + 1:
                q.append((next_t, t, cost + 1))
            elif dist_from_a[next_t] == cost:
                # 奇数距離で会う
                # cost+1//2とtとnext_tの間の辺を削除したグラフでtから最も遠い点までの距離の和
                x = t
                g[t].remove(next_t)
                g[next_t].remove(t)
                d_to_x = cost
                q = []
                break
            elif dist_from_a[next_t] == cost + 1:
                # 偶数距離で会う
                # cost+1//2とtとnext_tの間の辺を削除したグラフでtから最も遠い点までの距離の和
                x = t
                g[t].remove(next_t)
                g[next_t].remove(t)
                d_to_x = cost + 1
                q = []
                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()
