#include #include #include static std::mt19937 mt(0); static std::vector a, b; using Entry = std::pair; using Solution = std::vector; long calc_score(const Solution& ans, const std::vector& a, const std::vector& b) { std::vector aa = a; std::vector bb = b; for (auto [u,v] : ans) { long v1 = (aa[u] + aa[v])/2; long v2 = (bb[u] + bb[v])/2; aa[u] = v1; aa[v] = v1; bb[u] = v2; bb[v] = v2; } double v1 = std::abs(aa[0] - 5*1e17); double v2 = std::abs(bb[0] - 5*1e17); long score = 2000000L - 100000L * std::log10(std::max(v1, v2) + 1); return score; } void print_ans(const Solution& ans) { std::cout << ans.size() << std::endl; for (auto [u,v] : ans) { std::cout << u+1 << " " << v+1 << std::endl; } } auto gen_random_ans(int n) { constexpr int m = 50; std::vector ans; for (int i = 0; i < m; i++) { int u, v; while (true) { u = mt() % n; v = mt() % n; if (u != v) { break; } } ans.emplace_back(u,v); } return ans; } auto greedy_ans(int n) { constexpr int m = 50; std::vector ans; long best_score = calc_score(ans, a, b); std::cerr << "initial score: " << best_score << std::endl; for (int i = 0; i < m; i++) { std::cerr << i << " th iter" << std::endl; int u = 0; int best_v = -1; for (int v = 1; v < n; v++) { ans.emplace_back(u,v); long score = calc_score(ans, a, b); std::cerr << "v, score: " << v << ", " << score << std::endl; if (score > best_score) { best_score = score; best_v = v; } ans.pop_back(); } std::cerr << "best v, score: " << best_v << ", " << best_score << std::endl; if (best_v == -1) { break; } else { ans.emplace_back(u,best_v); } } return ans; } int main() { int n; std::cin >> n; a.resize(n); b.resize(n); for (int i = 0; i < n; i++) { std::cin >> a[i] >> b[i]; } auto ans = greedy_ans(n); std::cerr << "Final score: " << calc_score(ans, a, b) << std::endl; print_ans(ans); }