import sys
from collections import defaultdict, deque
from copy import deepcopy
import itertools
input = sys.stdin.readline
# 文字列の場合は普通のinput()を使うか下を使う
# input = sys.stdin.readline().rstrip()


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

# vを根にしたDFS
depth = [0] * N
leaf = []
parent = [None] * N
visited = [False] * N
q = deque([(v, 0)])
visited[v] = True
while q:
    w, h = q.popleft()
    is_leaf = True
    for s in repn[w]:
        if visited[s] == False:
            is_leaf = False
            visited[s] = True
            depth[s] = h + 1
            parent[s] = w
            q.append((s, h + 1))
    if is_leaf:
        leaf.append(w)
#print('depth={}'.format(depth))
#print('parent={}'.format(parent))
#print('leaf={}'.format(leaf))


# 各頂点から葉までの最長距離
height = [0] * N
q = deque([])
for w in leaf:
    q.append(w)
while q:
    w = q.popleft()
    s = parent[w]
    if s != None:
        height[s] = max(height[w] + 1, height[s])
        q.append(s)
#print('height={}'.format(height))


# 逃走経路の最長の長さ
mid = (depth[u] + 2) // 2
t = (depth[u] + 1) // 2
descend = height[u]
up = 0
p = parent[u]
for h in range(1, t):
    if descend + h < height[p]:
        descend = height[p]
        up = h
    p = parent[p]
length = descend + (depth[u] - up)
print(length - 1)