import sys
input = sys.stdin.readline
from collections import deque
import numpy as np

n, u, v = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n-1)]

graph = [[] for _ in range(n)]
for a, b in ab:
    graph[a-1].append(b-1)
    graph[b-1].append(a-1)


def dfs(graph, start):
    visited = [0]*n
    stack = deque([start])
    distance = [-1]*n
    dis = 0
    while stack:
        node = stack.pop()
        visited[node] = 1
        if len(graph[node]) == 1:
            if node == start:
                distance[node] = 0
            else:
                distance[node] = dis
                dis -= 1
        for child in graph[node]:
            if visited[child] == 1:
                continue
            stack.append(child)
        dis += 1
    return distance

distance1 = np.array(dfs(graph, u-1))
distance2 = np.array(dfs(graph, v-1))

distance = distance2[distance1<distance2]

print(min(distance)-1)
