#include using namespace std; class state { public: double x, y; uint64_t bit; int pre; state() : x(0.0), y(0.0), bit(0), pre(-1) {} state(double x_, double y_, uint64_t bit_, int pre_) : x(x_), y(y_), bit(bit_), pre(pre_) {} double score() const { return max(abs(x), abs(y)); } bool operator<(const state& s) const { return score() < s.score(); } }; int main() { // step #1. input int N; cin >> N; vector A(N), B(N); for (int i = 0; i < N; i++) { cin >> A[i] >> B[i]; A[i] -= 5.0e+17; B[i] -= 5.0e+17; } // step #2. beam search const int BEAMWIDTH = 18000; vector > beam(N); for (int i = 1; i < N; i++) { uint64_t bit = ((1ULL << N) - 1) ^ (1ULL << i); beam[0].push_back(state(A[i] * 0.5, B[i] * 0.5, bit, -1)); } sort(beam[0].begin(), beam[0].end()); if (int(beam[0].size()) > BEAMWIDTH) { beam[0].resize(BEAMWIDTH); } for (int level = 1; level <= N - 1; level++) { double mul = pow(0.5, min(level + 1, N - 1)); for (int i = 0; i < int(beam[level - 1].size()); i++) { state s = beam[level - 1][i]; uint64_t b = s.bit; while (b != 0) { int pos = __builtin_ctzll(b); b ^= 1ULL << pos; double x = s.x + A[pos] * mul; double y = s.y + B[pos] * mul; uint64_t bit = s.bit ^ (1ULL << pos); beam[level].push_back(state(x, y, bit, i)); } } if (int(beam[level].size()) > BEAMWIDTH) { nth_element(beam[level].begin(), beam[level].begin() + BEAMWIDTH, beam[level].end()); beam[level].resize(BEAMWIDTH); } // cerr << "level = " << level << ": size = " << beam[level].size() << ", score = " << (*min_element(beam[level].begin(), beam[level].end())).score() << ", back = " << beam[level].back().score() << endl; } // step #3. construct depth vector depth(N, -1); int idx = min_element(beam[N - 1].begin(), beam[N - 1].end()) - beam[N - 1].begin(); uint64_t prebit = beam[N - 1][idx].bit; for (int i = N - 1; i >= 0; i--) { uint64_t nxtbit = (i != 0 ? beam[i - 1][beam[i][idx].pre].bit : (1ULL << N) - 1); uint64_t bitdiff = prebit ^ nxtbit; depth[__builtin_ctzll(bitdiff)] = min(i + 1, N - 1); prebit = nxtbit; if (i != 0) { idx = beam[i][idx].pre; } } // step #4. construct answer vector > answer; vector curdepth = depth; while (curdepth[0] != 0) { int p1 = max_element(curdepth.begin(), curdepth.end()) - curdepth.begin(); int p2 = max_element(curdepth.begin() + p1 + 1, curdepth.end()) - curdepth.begin(); answer.push_back({p1, p2}); curdepth[p1] -= 1; curdepth[p2] = -1; } // step #5. output cout << answer.size() << endl; for (array v : answer) { cout << v[0] + 1 << ' ' << v[1] + 1 << endl; } return 0; }