import heapq
import numpy as np
N,u,v = map(int,input().split())
u -= 1
v -= 1

q = []
d = np.full([N], np.inf)
d[v] = 0
G = [0]*N
for i in range(N-1):
    e1,e2 = map(int, input().split())
    e1 -= 1
    e2 -= 1
    if G[e1] == 0:
        G[e1] = [e2]
    else:
        G[e1].append(e2)
    if G[e2] == 0:
        G[e2] = [e1]
    else:
        G[e2].append(e1)

if G[u]==[v]:
    ans = 0
else:    
    
    heapq.heappush(q,[0, v])
    d[v] = 0
    
    while q!=[]:
        p = heapq.heappop(q)
        pv = p[1]
        if d[pv] < p[0] :
            continue
        for i in range(len(G[pv])):
            eto = G[pv][i]
            if d[eto] > d[pv] + 1:
                 d[eto] = d[pv] + 1
                 heapq.heappush(q, [d[eto], eto])
    ans = int(np.amax(d)-1)
    
print(ans)