| #include <iostream> |
| #include <vector> |
| #include <algorithm> |
| #include <random> |
| #include <chrono> |
|
|
| using namespace std; |
|
|
| |
| |
| |
| bool adj(int x, int y) { |
| cout << "4 " << x << " " << y << " " << x << " " << y << endl; |
| cout.flush(); |
| int a, b, c, d; |
| cin >> a >> b >> c >> d; |
| return b == 1; |
| } |
|
|
| |
| |
| |
| pair<bool, bool> adj2(int x, int a, int b) { |
| cout << "6 " << x << " " << a << " " << a << " " << b << " " << b << " " << x << endl; |
| cout.flush(); |
| int r[6]; |
| for (int i = 0; i < 6; ++i) cin >> r[i]; |
| return {r[1] == 1, r[3] == 1}; |
| } |
|
|
| int main() { |
| ios::sync_with_stdio(false); |
| cin.tie(nullptr); |
|
|
| int subtask, n; |
| cin >> subtask >> n; |
|
|
| |
| mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); |
|
|
| vector<int> chain; |
| chain.push_back(1); |
|
|
| vector<int> rem; |
| for (int i = 2; i <= n; ++i) rem.push_back(i); |
|
|
| bool is_cycle = false; |
|
|
| while (!rem.empty()) { |
| |
| shuffle(rem.begin(), rem.end(), rng); |
|
|
| bool attached = false; |
| for (size_t idx = 0; idx < rem.size(); ++idx) { |
| int x = rem[idx]; |
| if (chain.size() == 1) { |
| |
| if (adj(x, chain[0])) { |
| chain.push_back(x); |
| rem.erase(rem.begin() + idx); |
| attached = true; |
| break; |
| } |
| } else { |
| int left = chain.front(); |
| int right = chain.back(); |
| auto [adjL, adjR] = adj2(x, left, right); |
| if (adjL && adjR) { |
| |
| chain.push_back(x); |
| rem.erase(rem.begin() + idx); |
| is_cycle = true; |
| attached = true; |
| break; |
| } else if (adjL) { |
| chain.insert(chain.begin(), x); |
| rem.erase(rem.begin() + idx); |
| attached = true; |
| break; |
| } else if (adjR) { |
| chain.push_back(x); |
| rem.erase(rem.begin() + idx); |
| attached = true; |
| break; |
| } |
| } |
| } |
| if (!attached) { |
| |
| |
| break; |
| } |
| } |
|
|
| |
| cout << "-1"; |
| for (int v : chain) cout << " " << v; |
| cout << endl; |
| cout.flush(); |
|
|
| return 0; |
| } |