import sys from time import time from random import random, randrange, choice, choices from heapq import heappop, heappush START = time() INF=10**9 def get_time(START): return time() - START def dist(p1,p2): x1,y1=p1 x2,y2=p2 return (x1-x2)**2 + (y1-y2)**2 def calc(i: int, j: int): d = dist(Terminals[ans[i]], Terminals[ans[j]]) if ans[i]