#include <bits/stdc++.h>
using namespace std;
const int N = 1001;
struct DSU {
vector<int> p;
vector<vector<int>> els;
DSU() {
p.resize(N);
els.resize(N);
iota(p.begin(), p.end(), 0);
for (int i = 0; i < N; ++i) {
els[i].push_back(i);
}
}
int get(int a) {
return p[a] = (a == p[a] ? a : get(p[a]));
}
void merge(int a, int b) {
int x = get(a);
int y = get(b);
if (x == y) return;
if (els[x].size() > els[y].size()) {
swap(x, y);
}
p[x] = y;
while (els[x].size()) els[y].push_back(els[x].back()), els[x].pop_back();
}
};
void build(vector<vector<int>> b);
int construct(vector<vector<int>> p) {
DSU lines;
const int n = p.size();
vector<vector<int>> b(n, vector<int>(n, 0));
for (int i = 0; i < n; ++i) {
for (int j = i+1; j < n; ++j) {
if (p[i][j] == 1) {
int x = lines.get(i);
int y = lines.get(j);
if (x != y) {
b[i][j] = b[j][i] = 1;
lines.merge(x, y);
}
}
}
}
DSU comps;
for (int i = 0; i < n; ++i) {
for (int j = i+1; j < n; ++j) {
if (p[i][j] > 0) comps.merge(i, j);
}
}
vector<bool> vis(n, false);
for (int i = 0; i < n; ++i) {
int j = comps.get(i);
if (vis[j]) continue;
vis[j] = true;
vector<int> vs = comps.els[j];
vector<int> twos;
vector<bool> vis_lines(n, false);
for (int k = 0; k < vs.size(); ++k) {
int v = vs[k];
if (vis_lines[lines.get(v)]) continue;
int u = lines.els[lines.get(v)].front();
twos.push_back(u);
vis_lines[lines.get(v)] = true;
}
if (twos.size() == 1) continue;
for (int k = 0; k < twos.size(); ++k) {
int nxt = (k+1)%twos.size();
b[twos[k]][twos[nxt]] = b[twos[nxt]][twos[k]] = 1;
}
}
build(b);
return true;
}
Compilation message
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:63:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
63 | for (int k = 0; k < vs.size(); ++k) {
| ~~^~~~~~~~~~~
supertrees.cpp:71:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
71 | for (int k = 0; k < twos.size(); ++k) {
| ~~^~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
5 ms |
1524 KB |
Output is correct |
7 |
Correct |
119 ms |
24052 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
5 ms |
1524 KB |
Output is correct |
7 |
Correct |
119 ms |
24052 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
432 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
5 ms |
1372 KB |
Output is correct |
13 |
Correct |
125 ms |
24220 KB |
Output is correct |
14 |
Incorrect |
1 ms |
344 KB |
Answer gives possible 1 while actual possible 0 |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Incorrect |
1 ms |
436 KB |
Answer gives possible 1 while actual possible 0 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
600 KB |
Output is correct |
4 |
Correct |
30 ms |
6484 KB |
Output is correct |
5 |
Correct |
123 ms |
24144 KB |
Output is correct |
6 |
Correct |
119 ms |
24328 KB |
Output is correct |
7 |
Correct |
123 ms |
24072 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
29 ms |
6300 KB |
Output is correct |
10 |
Correct |
153 ms |
24148 KB |
Output is correct |
11 |
Correct |
119 ms |
24144 KB |
Output is correct |
12 |
Correct |
119 ms |
24248 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
28 ms |
6268 KB |
Output is correct |
17 |
Correct |
114 ms |
24148 KB |
Output is correct |
18 |
Correct |
134 ms |
24184 KB |
Output is correct |
19 |
Correct |
120 ms |
24144 KB |
Output is correct |
20 |
Correct |
113 ms |
24144 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
5 ms |
1524 KB |
Output is correct |
7 |
Correct |
119 ms |
24052 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
432 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
5 ms |
1372 KB |
Output is correct |
13 |
Correct |
125 ms |
24220 KB |
Output is correct |
14 |
Incorrect |
1 ms |
344 KB |
Answer gives possible 1 while actual possible 0 |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
5 ms |
1524 KB |
Output is correct |
7 |
Correct |
119 ms |
24052 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
432 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
5 ms |
1372 KB |
Output is correct |
13 |
Correct |
125 ms |
24220 KB |
Output is correct |
14 |
Incorrect |
1 ms |
344 KB |
Answer gives possible 1 while actual possible 0 |
15 |
Halted |
0 ms |
0 KB |
- |