#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);
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Wrong Answer [2] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Wrong Answer [2] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
344 KB |
Output is correct |
2 |
Correct |
4 ms |
344 KB |
Output is correct |
3 |
Correct |
4 ms |
344 KB |
Output is correct |
4 |
Correct |
4 ms |
344 KB |
Output is correct |
5 |
Correct |
3 ms |
344 KB |
Output is correct |
6 |
Correct |
6 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
4 ms |
344 KB |
Output is correct |
3 |
Correct |
4 ms |
344 KB |
Output is correct |
4 |
Correct |
4 ms |
448 KB |
Output is correct |
5 |
Correct |
3 ms |
344 KB |
Output is correct |
6 |
Correct |
4 ms |
344 KB |
Output is correct |
7 |
Correct |
4 ms |
448 KB |
Output is correct |
8 |
Correct |
3 ms |
344 KB |
Output is correct |
9 |
Correct |
6 ms |
748 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
344 KB |
Output is correct |
2 |
Correct |
4 ms |
444 KB |
Output is correct |
3 |
Correct |
4 ms |
344 KB |
Output is correct |
4 |
Correct |
4 ms |
344 KB |
Output is correct |
5 |
Correct |
4 ms |
444 KB |
Output is correct |
6 |
Correct |
6 ms |
440 KB |
Output is correct |
7 |
Correct |
5 ms |
344 KB |
Output is correct |
8 |
Correct |
4 ms |
344 KB |
Output is correct |
9 |
Correct |
4 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Wrong Answer [2] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Wrong Answer [2] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
344 KB |
Output is correct |
2 |
Correct |
4 ms |
344 KB |
Output is correct |
3 |
Correct |
4 ms |
344 KB |
Output is correct |
4 |
Correct |
4 ms |
344 KB |
Output is correct |
5 |
Correct |
3 ms |
344 KB |
Output is correct |
6 |
Correct |
6 ms |
344 KB |
Output is correct |
7 |
Incorrect |
3 ms |
344 KB |
Wrong Answer [3] |
8 |
Halted |
0 ms |
0 KB |
- |