import sequtils,strutils,math,heapqueue type sen = tuple[b : int, d : float64 ] t = tuple[cost : float64, p : int] var N, M : int X, Y : int p,q : int dentyuu = newSeq[array[2,int]](0) densen = newSeqWith(200010, newSeq[sen](0)) hyou : array[200010, float64] (N, M) = stdin.readline.split.map(parseInt) (X, Y) = stdin.readline.split.map(parseInt) X -= 1 Y -= 1 for n in 1..N: (p,q) = stdin.readline.split.map(parseInt) dentyuu.add([p, q]) for m in 1..M: (p, q) = stdin.readline.split.map(parseInt) p -= 1 q -= 1 var dx : float = (dentyuu[p][0] - dentyuu[q][0]).float var dy : float = (dentyuu[p][1] - dentyuu[q][1]).float dx = dx * dx dy = dy * dy var d = sqrt(dx + dy) var l : sen = (q, d) densen[p].add(l) l = (p, d) densen[q].add(l) for i in 0..200000: hyou[i] = 1e10 var hp = initHeapQueue[t]() var i : t = (0.0, X) hp.push(i) while true: var P = hp.pop() if hyou[P.p] < P.cost: continue if P.p == Y: break hyou[P.p] = P.cost for s in densen[P.p]: if hyou[s[0]] > s[1] + hyou[P.p]: hp.push((s[1] + hyou[P.p], s[0])) hyou[s[0]] = s[1] + hyou[P.p] echo hyou[Y]