def greedy(cities,current_city,dist): N = len(cities) unvisited_cities = set(range(0, N)) tour = [current_city] unvisited_cities.remove(current_city) while unvisited_cities: next_city = min(unvisited_cities, key=lambda city: dist[current_city][city]) unvisited_cities.remove(next_city) tour.append(next_city) current_city = next_city return tour,dist def two_opt(tour, dist): N = len(tour) while True: count = 0 for i in range(N-2): for j in range(i+2, N): l1 = dist[tour[i]][tour[i + 1]] l2 = dist[tour[j]][tour[(j + 1) % N]] l3 = dist[tour[i]][tour[j]] l4 = dist[tour[i + 1]][tour[(j + 1) % N]] if l1 + l2 > l3 + l4: new_tour = tour[i+1 : j+1] tour[i+1 : j+1] = new_tour[::-1] count += 1 if count == 0: break return tour # ==================== N, M = map(int, input().split()) planet = [tuple(map(int, input().split())) for _ in range(N)] dist = [[0 for _ in range(N)] for _ in range(N)] for i in range(N): for j in range(N): p1 = planet[i] p2 = planet[j] D = (p1[0] - p2[0]) ** 2 + (p1[1] - p2[1]) ** 2 dist[i][j] = D tour, dis = greedy(planet, 0, dist) tour = two_opt(tour, dis) for _ in range(M):print(*planet[16]) print(len(tour)+1) for i in range(len(tour)):print(1, tour[i]+1) print(1, 1)