#include "island.h"
#include <bits/stdc++.h>
using namespace std;
void solve(int N, int L) {
vector<bool> found(N + 1);
found[1] = true;
// Iterate over the BFS starting at 1
for (int k = 1; k < N; k ++) {
int i = query(1, k); // N queries
// found represents if the parent is already linked to the node
// if yes we don't have anything to do
if (found[i]) continue ;
found[i] = true;
// otherwise we search for the adjacent nodes, if it is the parent we stop
// otherwise we set the next to found and answer that.
// thus each link is visited once for N - 1 queries
int off = 1;
int nxt = -1;
do {
if (nxt != -1) found[nxt] = true;
nxt = query(i, off ++);
answer(i, nxt);
} while (!found[nxt]);
}
}
# | 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... |