""" 最初の①にかける時間を少なくした。その分、②により多くの時間がさける ①ランダムにステーションを配置して各惑星から最も近いステーションまでのコストの和が最小になる解を山登りで見つける ②次に2点swapでコストの和が最小になる道順を時間いっぱいまで山登りで探索 """ from random import randint,shuffle,sample from time import time # ダイクストラ(惑星専用) def dijkstra(start = 0, INF=10**20): from heapq import heappop, heappush d = [INF for i in range(len(G))] prev = [-1]*len(G) d[start] = 0 que = [] heappush(que, (0, start)) while que: d_, v = heappop(que) if d[v] < d_: continue for u, c in G[v].items(): if d[u] > d[v] + c: d[u] = d[v] + c prev[u] = v heappush(que, (d[u], u)) return d,prev # sからtまでの最短経路を復元 def recover_path(s,t): prev = PREV[s] path = [t] while prev[t] != -1: t = prev[t] path.append(t) return path[::-1] # 道順を与えられたときに距離を返す def calc_score(path): assert len(path) == N+1, "The length of path should be N+1" score = 0 for i in range(N): score += D[path[i]][path[i+1]] return score stime = time() N,M = map(int,input().split()) AB = [tuple(map(int,input().split())) for _ in range(N)] AB2 = {} for a,b in AB: if a not in AB2: AB2[a] = set() AB2[a].add(b) alpha = 5 res2 = 10**30 argmin = [] for itr in range(1000): CD = [] for i in range(M): c,d = randint(0,999),randint(0,999) while c in AB2 and d in AB2[c]: c,d = randint(0,999),randint(0,999) CD.append((c,d)) res = 0 for a,b in AB: MIN = 10**20 for c,d in CD: MIN = min(MIN,(c-a)**2+(d-b)**2) res += MIN if res < res2: res2 = res argmin = CD CD = argmin G = [{} for _ in range(N+M)] for i in range(N+M-1): if i < N: x1,y1 = AB[i] else: x1,y1 = CD[i-N] for j in range(i+1,N+M): if j < N: x2,y2 = AB[j] else: x2,y2 = CD[j-N] dist = (x2-x1)**2 + (y2-y1)**2 if i 0.8: break i,j = sample(range(N-1),2) ans[i],ans[j] = ans[j],ans[i] score2 = calc_score([0]+ans+[0]) if score2 < score: score = score2 else: ans[i],ans[j] = ans[j],ans[i] ans = [0]+ans+[0] all_path = [ans[0]] for i in range(N): s,t = ans[i],ans[i+1] path = recover_path(s,t) for j in range(len(path)-1): all_path.append(path[j+1]) #print(score) #print(all_path) for c,d in CD: print(c,d) print(len(all_path)) for idx in all_path: if idx < N: t = 1 else: t = 2 idx -= N print(t,idx+1)