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

import heapq
def dijkstra_heap(s):
    #始点sから各頂点への最短距離
    d = [float("inf")] * n
    used = [True] * n #True:未確定
    d[s] = 0
    used[s] = False
    edgelist = []
    for e in edge[s]:
        heapq.heappush(edgelist,e)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        #まだ使われてない頂点の中から最小の距離のものを探す
        if not used[minedge[1]]:
            continue
        v = minedge[1]
        d[v] = minedge[0]
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,[e[0]+d[v],e[1]])
    return d

#n,w = map(int,input().split()) #n:頂点数　w:辺の数
edge = [[] for i in range(n)]
#edge[i] : iから出る道の[重み,行先]の配列
for i in range(n-1):
    z=1
    x,y = map(int,input().split())
    x-=1;y-=1
    edge[x].append([z,y]) #有向辺
    edge[y].append([z,x]) #有向辺
A=dijkstra_heap(u)
B=dijkstra_heap(v)
l=[]
#print(A)
#print(B)
for i in range(n):
    l.append([A[i],B[i]])
l.sort()
l=l[::-1]
#print(l)
ans_1=float('inf')
ans_2=float('inf')
for i in range(n):
    if l[i][0]+1==l[i][1]:
        ans_1=l[i][0]
        break
for i in range(n):
        if l[i][0]==l[i][1]:
            ans_2=l[i][0]
print(min(ans_1,ans_2))
