#include <bits/stdc++.h>
#include "supertrees.h"
using namespace std;
void build(vector<vector<int>> b);
struct DSU {
vector<int> link, siz;
DSU (int n) : link(n), siz(n, 1) {
iota(link.begin(), link.end(), 0ll);
}
int get(int x) {
if (link[x] == x) {
return x;
}
return link[x] = get(link[x]);
}
bool unite(int a, int b) {
a = get(a), b = get(b);
if (a == b) {
return false;
}
if (siz[a] < siz[b]) {
swap(a, b);
}
link[b] = a;
siz[a] += siz[b];
return true;
}
bool same(int a, int b) {
return (get(a) == get(b));
}
};
int construct(vector<vector<int>> p) {
vector<vector<int>> b(p.size(), vector<int>(p.size()));
DSU ds(p.size());
for (int i = 0; i < p.size(); i++) {
for (int j = i + 1; j < p.size(); j++) {
if (p[i][j] != 0) {
ds.unite(i, j);
}
}
}
for (int i = 0; i < p.size(); i++) {
for (int j = i + 1; j < p.size(); j++) {
if (p[i][j] == 0 && ds.same(i, j)) {
return 0;
} else if (p[i][j] == 1 && !ds.same(i, j)) {
return 0;
}
}
}
vector<vector<int>> conncomps(p.size());
for (int i = 0; i < p.size(); i++) {
conncomps[ds.get(i)].push_back(i);
}
for (int i = 0; i < conncomps.size(); i++) {
for (int j = 0; j < (int) conncomps[i].size() - 1; j++) {
b[conncomps[i][j]][conncomps[i][j + 1]] = 1;
b[conncomps[i][j + 1]][conncomps[i][j]] = 1;
}
}
build(b);
return 1;
}
Compilation message
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:45:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
45 | for (int i = 0; i < p.size(); i++) {
| ~~^~~~~~~~~~
supertrees.cpp:46:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
46 | for (int j = i + 1; j < p.size(); j++) {
| ~~^~~~~~~~~~
supertrees.cpp:53:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
53 | for (int i = 0; i < p.size(); i++) {
| ~~^~~~~~~~~~
supertrees.cpp:54:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
54 | for (int j = i + 1; j < p.size(); j++) {
| ~~^~~~~~~~~~
supertrees.cpp:64:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
64 | for (int i = 0; i < p.size(); i++) {
| ~~^~~~~~~~~~
supertrees.cpp:68:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
68 | for (int i = 0; i < conncomps.size(); i++) {
| ~~^~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
6 ms |
1108 KB |
Output is correct |
7 |
Correct |
147 ms |
22068 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
6 ms |
1108 KB |
Output is correct |
7 |
Correct |
147 ms |
22068 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
7 ms |
1236 KB |
Output is correct |
13 |
Correct |
146 ms |
22284 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
304 KB |
Output is correct |
16 |
Correct |
3 ms |
864 KB |
Output is correct |
17 |
Correct |
70 ms |
12320 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
300 KB |
Output is correct |
20 |
Correct |
37 ms |
5828 KB |
Output is correct |
21 |
Correct |
149 ms |
22336 KB |
Output is correct |
22 |
Correct |
151 ms |
22348 KB |
Output is correct |
23 |
Correct |
156 ms |
22316 KB |
Output is correct |
24 |
Correct |
158 ms |
22300 KB |
Output is correct |
25 |
Correct |
61 ms |
12300 KB |
Output is correct |
26 |
Correct |
60 ms |
12344 KB |
Output is correct |
27 |
Correct |
153 ms |
22240 KB |
Output is correct |
28 |
Correct |
153 ms |
22300 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
308 KB |
Output is correct |
4 |
Incorrect |
1 ms |
296 KB |
Answer gives possible 1 while actual possible 0 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Incorrect |
1 ms |
300 KB |
Too few ways to get from 0 to 1, should be 2 found 1 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
6 ms |
1108 KB |
Output is correct |
7 |
Correct |
147 ms |
22068 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
7 ms |
1236 KB |
Output is correct |
13 |
Correct |
146 ms |
22284 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
304 KB |
Output is correct |
16 |
Correct |
3 ms |
864 KB |
Output is correct |
17 |
Correct |
70 ms |
12320 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
300 KB |
Output is correct |
20 |
Correct |
37 ms |
5828 KB |
Output is correct |
21 |
Correct |
149 ms |
22336 KB |
Output is correct |
22 |
Correct |
151 ms |
22348 KB |
Output is correct |
23 |
Correct |
156 ms |
22316 KB |
Output is correct |
24 |
Correct |
158 ms |
22300 KB |
Output is correct |
25 |
Correct |
61 ms |
12300 KB |
Output is correct |
26 |
Correct |
60 ms |
12344 KB |
Output is correct |
27 |
Correct |
153 ms |
22240 KB |
Output is correct |
28 |
Correct |
153 ms |
22300 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
1 ms |
212 KB |
Output is correct |
31 |
Correct |
1 ms |
308 KB |
Output is correct |
32 |
Incorrect |
1 ms |
296 KB |
Answer gives possible 1 while actual possible 0 |
33 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
6 ms |
1108 KB |
Output is correct |
7 |
Correct |
147 ms |
22068 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
7 ms |
1236 KB |
Output is correct |
13 |
Correct |
146 ms |
22284 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
304 KB |
Output is correct |
16 |
Correct |
3 ms |
864 KB |
Output is correct |
17 |
Correct |
70 ms |
12320 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
300 KB |
Output is correct |
20 |
Correct |
37 ms |
5828 KB |
Output is correct |
21 |
Correct |
149 ms |
22336 KB |
Output is correct |
22 |
Correct |
151 ms |
22348 KB |
Output is correct |
23 |
Correct |
156 ms |
22316 KB |
Output is correct |
24 |
Correct |
158 ms |
22300 KB |
Output is correct |
25 |
Correct |
61 ms |
12300 KB |
Output is correct |
26 |
Correct |
60 ms |
12344 KB |
Output is correct |
27 |
Correct |
153 ms |
22240 KB |
Output is correct |
28 |
Correct |
153 ms |
22300 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
1 ms |
212 KB |
Output is correct |
31 |
Correct |
1 ms |
308 KB |
Output is correct |
32 |
Incorrect |
1 ms |
296 KB |
Answer gives possible 1 while actual possible 0 |
33 |
Halted |
0 ms |
0 KB |
- |