#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 - 1; 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 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
6 ms |
452 KB |
Output is correct |
6 |
Correct |
5 ms |
344 KB |
Output is correct |
7 |
Correct |
6 ms |
600 KB |
Output is correct |
8 |
Correct |
5 ms |
344 KB |
Output is correct |
9 |
Correct |
5 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
344 KB |
Output is correct |
2 |
Correct |
6 ms |
856 KB |
Output is correct |
3 |
Correct |
4 ms |
452 KB |
Output is correct |
4 |
Correct |
4 ms |
344 KB |
Output is correct |
5 |
Correct |
3 ms |
344 KB |
Output is correct |
6 |
Correct |
7 ms |
600 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
6 ms |
440 KB |
Output is correct |
3 |
Correct |
4 ms |
344 KB |
Output is correct |
4 |
Correct |
6 ms |
448 KB |
Output is correct |
5 |
Correct |
4 ms |
344 KB |
Output is correct |
6 |
Correct |
5 ms |
452 KB |
Output is correct |
7 |
Correct |
4 ms |
600 KB |
Output is correct |
8 |
Correct |
5 ms |
600 KB |
Output is correct |
9 |
Correct |
5 ms |
600 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
344 KB |
Output is correct |
2 |
Correct |
6 ms |
432 KB |
Output is correct |
3 |
Correct |
4 ms |
344 KB |
Output is correct |
4 |
Correct |
4 ms |
344 KB |
Output is correct |
5 |
Correct |
6 ms |
444 KB |
Output is correct |
6 |
Correct |
6 ms |
344 KB |
Output is correct |
7 |
Correct |
6 ms |
512 KB |
Output is correct |
8 |
Correct |
5 ms |
344 KB |
Output is correct |
9 |
Correct |
4 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
6 ms |
452 KB |
Output is correct |
6 |
Correct |
5 ms |
344 KB |
Output is correct |
7 |
Correct |
6 ms |
600 KB |
Output is correct |
8 |
Correct |
5 ms |
344 KB |
Output is correct |
9 |
Correct |
5 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
6 ms |
440 KB |
Output is correct |
12 |
Correct |
4 ms |
344 KB |
Output is correct |
13 |
Correct |
6 ms |
448 KB |
Output is correct |
14 |
Correct |
4 ms |
344 KB |
Output is correct |
15 |
Correct |
5 ms |
452 KB |
Output is correct |
16 |
Correct |
4 ms |
600 KB |
Output is correct |
17 |
Correct |
5 ms |
600 KB |
Output is correct |
18 |
Correct |
5 ms |
600 KB |
Output is correct |
19 |
Incorrect |
6 ms |
452 KB |
Wrong Answer [5] |
20 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
5 ms |
344 KB |
Output is correct |
5 |
Correct |
6 ms |
432 KB |
Output is correct |
6 |
Correct |
4 ms |
344 KB |
Output is correct |
7 |
Correct |
4 ms |
344 KB |
Output is correct |
8 |
Correct |
6 ms |
444 KB |
Output is correct |
9 |
Correct |
6 ms |
344 KB |
Output is correct |
10 |
Correct |
6 ms |
512 KB |
Output is correct |
11 |
Correct |
5 ms |
344 KB |
Output is correct |
12 |
Correct |
4 ms |
344 KB |
Output is correct |
13 |
Incorrect |
5 ms |
600 KB |
Wrong Answer [5] |
14 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
344 KB |
Output is correct |
2 |
Correct |
6 ms |
856 KB |
Output is correct |
3 |
Correct |
4 ms |
452 KB |
Output is correct |
4 |
Correct |
4 ms |
344 KB |
Output is correct |
5 |
Correct |
3 ms |
344 KB |
Output is correct |
6 |
Correct |
7 ms |
600 KB |
Output is correct |
7 |
Incorrect |
3 ms |
344 KB |
Wrong Answer [3] |
8 |
Halted |
0 ms |
0 KB |
- |