#include #include #include #include #include #include #include #define mkt make_tuple #define rep(i, n) for (int i = 0; i < (int)(n); ++i) #define all(v) v.begin(), v.end() using namespace std; using ll = long long; template void chmin(T &a, const T &b) { if (a > b) a = b; } template void chmax(T &a, const T &b) { if (a < b) a = b; } constexpr int N = 100; constexpr int M = 8; constexpr int ALPHA = 5; constexpr int PLANET = 1; constexpr int STATION = 2; class Timer { public: chrono::time_point start; Timer() {} void init() { start = chrono::system_clock::now(); } int get_ms() { auto cur = chrono::system_clock::now(); return chrono::duration_cast(cur - start).count(); } }; struct Coordinate { int x; int y; Coordinate(int x = -1, int y = -1) : x(x), y(y) {} bool operator==(const Coordinate &rhs) const { return x == rhs.x && y == rhs.y; } bool operator!=(const Coordinate &rhs) const { return x != rhs.x || y != rhs.y; } int get_manhattan_dist(const Coordinate &other) const { int dx = abs(x - other.x); int dy = abs(y - other.y); return dx + dy; } int get_euclid_dist_squared(const Coordinate &other) const { int dx = abs(x - other.x); int dy = abs(y - other.y); return dx * dx + dy * dy; } }; class DisjointSet { public: int N; vector par, rank; vector sz; DisjointSet() {} DisjointSet(int N) : N(N), par(N), rank(N), sz(N) { for (int i = 0; i < N; i++) make_set(i); } bool same(int x, int y) { return leader(x) == leader(y); } void unite(int x, int y) { if (same(x, y)) return; link(leader(x), leader(y)); } int leader(int x) { if (x != par[x]) par[x] = leader(par[x]); return par[x]; } int size(int x) { return sz[leader(x)]; } private: void make_set(int x) { par[x] = x; rank[x] = 0; sz[x] = 1; } void link(int x, int y) { if (rank[x] > rank[y]) swap(x, y); par[x] = y; sz[y] += sz[x]; if (rank[x] == rank[y]) { ++rank[y]; } } }; struct Planet { int id; Coordinate pos; Planet(int id, Coordinate pos) : id(id), pos(pos) {} }; struct Station { int id; Coordinate pos; Station(int id, Coordinate pos) : id(id), pos(pos) {} }; struct Input { vector planets; Input(vector planets) : planets(planets) {} }; struct Output { int type; int id; Output(int type, int id) : type(type), id(id) {} }; Timer timer; Input read_input() { // Timer timer; timer.init(); int n, m; cin >> n >> m; vector planets; for (int i = 0; i < N; i++) { int a, b; cin >> a >> b; planets.emplace_back(i, Coordinate(a, b)); } Input input(planets); return input; } void output(vector stations, vector outputs) { for (auto stat : stations) cout << stat.pos.x << " " << stat.pos.y << "\n"; cout << outputs.size() << "\n"; for (auto out : outputs) cout << out.type << " " << out.id + 1 << "\n"; } vector make_outputs(const vector &planets, const vector &stations) { vector objects; rep(i, N) objects.emplace_back(planets[i].pos); rep(i, M) objects.emplace_back(stations[i].pos); const int V = objects.size(); using EDGE = tuple; vector edges; for (int i = 0; i < V; i++) for (int j = 0; j < i; j++) { int coef = 1; if (i < N) coef *= 5; if (j < N) coef *= 5; int cost = coef * objects[i].get_euclid_dist_squared(objects[j]); edges.push_back(mkt(cost, i, j)); } sort(all(edges)); DisjointSet uf(V); vector> g(V); for (auto [cost, a, b] : edges) { if (uf.same(a, b)) continue; uf.unite(a, b); g[a].push_back(b); g[b].push_back(a); } vector outputs; auto dfs = [&](auto &&dfs, int now, int par) -> void { for (auto to : g[now]) { if (to == par) continue; if (to < N) outputs.emplace_back(PLANET, to); else outputs.emplace_back(STATION, to - N); dfs(dfs, to, now); if (now < N) outputs.emplace_back(PLANET, now); else outputs.emplace_back(STATION, now - N); } }; outputs.emplace_back(PLANET, 0); dfs(dfs, 0, -1); return outputs; } void solve(const Input &input) { vector stations; // rep(i, M) stations.emplace_back(i, Coordinate(0, 0)); rep(i, M) stations.emplace_back(i, input.planets[i].pos); /* vector outputs; for (int i = 0; i < N; i++) outputs.emplace_back(PLANET, input.planets[i].id); outputs.emplace_back(PLANET, input.planets[0].id); */ vector outputs = make_outputs(input.planets, stations); output(stations, outputs); cerr << "end time: " << timer.get_ms() << "[ms]" << endl; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); Input input = read_input(); solve(input); return 0; }