from collections import deque

di_lst = []
N, U, V = map(int, input().split())
edges = {tuple(map(int, input().split())) for i in range(N - 1)}

stack = deque()


def BFS(X, edges, N):
    roots = [set() for _ in range(N + 1)]
    for a, b in edges:
        roots[a].add(b)
        roots[b].add(a)
    dist = {}
    stack = deque()
    stack.append(X)
    dist[X] = 0
    while stack:
        parent = stack.pop()
        for child in roots[parent]:
            if not child in dist:
                dist[child] = dist[parent] + 1
                stack.append(child)
    return dist


U_dist = BFS(U, edges, N)
V_dist = BFS(V, edges, N)

ans = 0
for i in range(1, N + 1):
    u, v = U_dist[i], V_dist[i]
    if u > v:
        ans = max(v - 1, ans)
print(ans)
