from collections import deque, defaultdict

N ,u, v = map(int,input().split())
graph = defaultdict(deque)
for _ in range(1,N):
    a, b = map(int,input().split())
    graph[a].append(b)
    graph[b].append(a)

depth = dict(zip(list(range(1,N+1)),[-1]*N))

def bfs(s):
    if graph[s]:
        for v in graph[s]:
            if depth[v] == -1:
                depth[v] = depth[s] + 1
                bfs(v)

depth[v] = 0
bfs(v)
MAX = 0

if depth[u] <= 2:
    print(depth[u]- 1)
else:
    print(max(depth.values())-1)