from collections import deque
INFTY = 10**6
N,u,v = map(int,input().split())
G = {i:[] for i in range(1,N+1)}
for _ in range(N-1):
    a,b = map(int,input().split())
    G[a].append(b)
    G[b].append(a)
pre = {i:[] for i in range(1,N+1)}        
que = deque([(u,0)])
hist = [0 for _ in range(N+1)]
hist[u] = 1
dist = [0 for _ in range(N+1)]
dist[u] = 0
while que:
    x,d = que.popleft()
    for y in G[x]:
        if hist[y]==0:
            que.append((y,d+1))
            hist[y] = 1
            dist[y] = d+1
            pre[y].append(x)
w = dist[v]
cnt = (w-1)//2
a = u
i = 0
while i<cnt:
    a = pre[a][0]
    i += 1
b = pre[a][0]
que = deque([(a,0)])
hist = [0 for _ in range(N+1)]
hist[a] = 1
hist[b] = 1
dist2 = [0 for _ in range(N+1)]
while que:
    x,d = que.popleft()
    for y in G[x]:
        if hist[y]==0:
            que.append((y,d+1))
            hist[y] = 1
            dist2[y] = d+1
d = max(dist2)
if w%2==1:
    print(cnt+d)
else:
    print(cnt+d+1)