#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);
    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;
            while (k < N - 1) {
                int u = ask(v, k);
                if (parent[v] != -1) break;
                parent[u] = v;
                q.push(u);
                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... |