N,u,v = map(int,input().split())
u -= 1
v -= 1

du = [0]*N
dv = [0]*N
du[u] = 0
dv[v] = 0
G = [[]]*N

def dfs(v, d, p, dis):
    dis[v] = d
    if G[v] != 0:
        for u in G[v]:
            if( u == p):
                continue
            else:
                dfs( u, d+1, v, dis )

def calcDist(s, dist):
    dfs(s, 0, -1, dist)

for i in range(N-1):
    e1,e2 = map(int, input().split())
    e1 -= 1
    e2 -= 1
    if G[e1] == []:
        G[e1] = [e2]
    else:
        G[e1].append(e2)
    if G[e2] == []:
        G[e2] = [e1]
    else:
        G[e2].append(e1)

if G[u]==[v]:
    ans = 0
else:    

    calcDist(v,dv)
    calcDist(u,du)
    maxD = 0
    for idu,idv in zip(du,dv):
        if idu < idv:
            maxD = max(maxD, idv)       
    ans = maxD-1
    
print(ans)