#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #if defined(_MSC_VER) || defined(__APPLE_CC__) #define LOCAL #endif const int TIME_LIMIT = 6000 - 100; const int INF = 1000000000; typedef pair II; std::random_device seed_gen; std::mt19937_64 engine(seed_gen()); auto start_time = chrono::high_resolution_clock::now(); inline int get_elapsed_ms() { return int(chrono::duration_cast(chrono::high_resolution_clock::now() - start_time).count()); } struct Solver { int N; int M; vector y, x, g; void input() { cin >> N >> M; y.resize(N + M); x.resize(N + M); g.resize(N + M); for (int i = 0; i < N; ++i) { cin >> y[i] >> x[i]; } } void prepare() { } void output(const vector& ans) { for (int i = 0; i < M; ++i) { cout << y[i + N] << " " << x[i + N] << endl; } cout << ans.size() << endl; for (int x : ans) { if (x < N) { cout << "1 " << (x + 1) << endl; } else { cout << "2 " << (x - N + 1) << endl; } } } void classify() { for (int i = 0; i < N; ++i) { g[i] = engine() % M; } bool done = false; while (!done) { done = true; vector xx(M), yy(M), cnt(M); for (int i = 0; i < N; ++i) { xx[g[i]] += x[i]; yy[g[i]] += y[i]; cnt[g[i]] += 1; } for (int i = 0; i < M; ++i) { if (cnt[i]) { xx[i] /= cnt[i]; yy[i] /= cnt[i]; x[N + i] = xx[i]; y[N + i] = yy[i]; } } for (int i = 0; i < N; ++i) { int md = INF, next_g = -1; for (int j = 0; j < M; ++j) { int dx = x[i] - xx[j], dy = y[i] - yy[j], d = dx * dx + dy * dy; if (d < md) { md = d; next_g = j; } } if (g[i] != next_g) { done = false; g[i] = next_g; } } } } vector gen(const vector &seq) { vector r; for (int gg = 0; gg < M; ++gg) { int tg = seq[gg]; for (int i = 0; i < N; ++i) { if (g[i] == tg) { r.emplace_back(i); r.emplace_back(N + tg); } } r.emplace_back(N + seq[gg + 1]); } r.emplace_back(0); return r; } int64_t evaluate(const vector& r) { int64_t s = 0; int p = 0; for (int next : r) { int dx = x[next] - x[p], dy = y[next] - y[p]; int64_t d = dx * dx + dy * dy; if (p < N) d *= 5; if (next < N) d *= 5; p = next; s += d; } return s; } void run() { int64_t min_score = 1LL << 60; vector ans; classify(); vector seq(M+1); iota(seq.begin(), seq.end(), 0); seq[M] = g[0]; do { if (seq[0] == g[0]) { vector r = gen(seq); int64_t score = evaluate(r); if (score < min_score) { min_score = score; ans = r; } } } while (next_permutation(seq.begin(), seq.begin() + M)); output(ans); } }; int main(int argc, char* argv[]) { #if DEBUG freopen("in.txt", "r", stdin); #endif Solver solver; solver.input(); solver.prepare(); solver.run(); }