This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "island.h"
#include <bits/stdc++.h>
using namespace std;
vector<int> p, done;
vector<pair<int, int>> e;
bool ok[301][301];
int find(int u) {
return p[u] == u ? u : p[u] = find(p[u]);
}
bool merge(int u, int v, int f = 1) {
int pu = find(u), pv = find(v);
if (pu == pv) return false;
if (f) {
p[pv] = pu;
e.emplace_back(u, v);
}
return true;
}
void solve(int N, int L) {
p.resize(N + 1);
done.assign(N + 1, 0);
for (int i = 1; i <= N; i++) p[i] = i;
for (int iter = 1; iter <= N; iter++) {
vector<pair<int, int>> t;
for (int i = 1; i <= N; i++) {
if (done[i]) continue;
int x = query(i, iter);
// cout << i << " " << iter << " " << x << '\n';
if (x > i || !merge(i, x, 0)) done[i] = 1;
else t.push_back({i, x});
}
for (auto& [x, y] : t) merge(x, y);
}
for (auto& [x, y] : e) {
if (ok[x][y]) continue;
ok[x][y] = ok[y][x] = 1;
// cout << x << ' ' << y << '\n';
answer(x, y);
}
}
# | 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... |