#include "island.h"
#include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define ar array
using namespace std;
typedef long long ll;
const int N = 303;
int a[N][N], vis[N], f[N], sz[N], add[N];
int father(int x) {
if (f[x] != f[f[x]])
return f[x] = father(f[x]);
return f[x];
}
void dsu(int u, int v) {
u = father(u), v = father(v);
if (u == v)
return;
if (sz[u] < sz[v])
swap(u, v);
sz[u] += sz[v];
f[v] = u;
}
void solve(int n, int l) {
for (int i = 1; i <= n; i++)
f[i] = i, sz[i] = 1;
int k = 1, cnt = 1;
while (cnt < n) {
int x = query(1, k);
// cout << x << ' ' << flush;
if (father(1) == father(x)) {
k++;
continue;
}
int t = 1, y, f = -1, c = -1;
do {
y = query(x, t);
c++;
if (f == -1)
f = y;
dsu(x, y);
a[x][y] = a[y][x] = 1, cnt++, t++;
} while (father(y) != father(1));
k++;
}
for (int i = 1; i <= n; i++)
for (int j = 1; j < i; j++)
if (a[i][j])
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... |