#include "island.h"
#include "bits/stdc++.h"
using namespace std;
template<typename T>
using vec = vector<T>;
void solve(int N, int L) {
    map<pair<int, int>, int> mp;
    auto ask = [&](int a, int b) {
        a++;
        b++;
        if (mp.contains({a, b})) return mp[{a, b}];
        return mp[{a, b}] = query(a, b) - 1;
    };
    vec<int> parent(N, -1);
    parent[0] = 0;
    queue<int> q;
    q.push(0);
    while (!q.empty()) {
        auto v = q.front();
        q.pop();
        if (v == 0) {
            int k = 0;
            while (k < N - 1) {
                int u = ask(v, k);
                if (ask(u, 0) != 0) break;
                parent[u] = v;
                q.push(u);
                answer(v + 1, u + 1);
                k++;
            }
        } else {
            int k = 0;
            set<int> bad;
            while (k < N - 1) {
                int u = ask(v, k);
                if (u == parent[v]) {
                    k++;
                    continue;
                }
                if (bad.contains(u)) break;
                if (parent[u] != -1 ) break;
                parent[u] = v;
                q.push(u);
                if (ask(u, 0) == v)
                    bad.insert(ask(u, 1));
                else bad.insert(ask(u, 0));
                answer(v + 1, u + 1);
                k++;
            }
        }
    }
}
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |