#include "island.h"
#include <bits/stdc++.h>
using namespace std;
#define MAXN 301
#define nl '\n'
#define ff first
#define ss second
#define ll long long
#define ld long double
#define terminator main
#define pll pair<ll,ll>
#define add insert
#define append push_back
#define pii pair<int,int>
#define all(x) (x).begin(),(x).end()
#define L0TA ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
int k[MAXN];
int c[MAXN];
vector<int> G[MAXN];
bool nei[MAXN][MAXN];
void join(int i, int j){
    int k = c[j];
    for(auto & v : G[k]){
        G[c[i]].append(v);
        c[v] = c[i];
    }
    G[k].clear();
}
void solve(int n, int l){
    int j, e;
    vector<pii> s, t;
    map<pii, vector<int>> x;
    for(int i = 1; i <= n; i++){
        s.append({0, i});
        G[i].append(i);
        c[i] = i;
        k[i] = 1;
    }
    e = 0;
    for(int it = 1; e < n - 1; it++){
        for(auto & [p, i] : s){
            if(l < 3 * n && k[i] > 2)
                continue;
            j = query(i, k[i]);
            k[i]++;
            if(j < p) continue;
            if(nei[j][i]){
                if(c[i] != c[j]){
                    nei[i][j] = 1;
                    t.append({j, i});
                    t.append({i, j});
                    join(i, j);
                    e++;
                }
            }
            else nei[i][j] = 1;
        }
        swap(s, t);
        t.clear();
        x.clear();
    }
    for(int i = 1; i < n; i++)
        for(int j = i + 1; j <= n; j++)
            if(nei[i][j] && nei[j][i]) 
                answer(i, j);
}
| # | 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... |