def search(tree, self, dist, d):
    dist[self] = d
    for num in tree[self]:
        if(dist[num] == -1 or dist[num] > d):
            search(tree, num, dist, d+1)

N, U, V = map(int, input().split())
tree = [[] for _ in range(N + 1)]

for _ in range(N - 1):
    A, B = map(int, input().split())
    tree[A].append(B)
    tree[B].append(A)

dist_a = [-1] * (N+1)
dist_b = [-1] * (N+1)

search(tree, U, dist_a, 0)
search(tree, V, dist_b, 0)

ans = 0

for i in range(1, N+1):
    if (dist_a[i] < dist_b[i]):
        ans = max(ans, dist_b[i])

print(ans - 1)
