#include "supertrees.h"
#include <vector>
#include <cassert>
#include <numeric>
using namespace std;
template <typename T>
bool operator==(vector<T> &a, vector<T> &b){
for (int i = 0; i < a.size(); ++i) {
if (a[i] != b[i]) return false;
}
return true;
}
template <typename T>
bool operator!=(vector<T> &a, vector<T> &b){
return !(a==b);
}
struct Unionfind {
vector<int> group;
Unionfind(int n) {
group.resize(n);
iota(group.begin(), group.end(), 0);
}
int find(int i){
if (group[i] == i) return i;
return group[i] = find(group[i]);
}
void merge(int a, int b){
a = find(a); b = find(b);
if (a == b) return;
group[b] = group[a];
}
};
int construct(vector<vector<int>> p) {
int n = p.size();
vector<vector<int>> res (n);
vector<bool> inc (n);
Unionfind unionfind (n);
for (int i = 0; i < n; ++i) {
for (int j = i + 1; j < n; ++j) {
if (p[i][j] != 0) unionfind.merge(i, j);
}
}
for (int i = 0; i < n; ++i) {
for (int j = i + 1; j < n; ++j) {
if ((p[i][j] == 0) && (unionfind.find(i) == unionfind.find(j))) return 0;
}
}
for (int i = 0; i < n; ++i) {
if (!res[i].empty()) continue;
res[i].assign(n, 0);
inc[i] = true;
for (int j = 0; j < n; ++j) {
if (p[i][j] == 0 || i == j) continue;
if (p[i][j] == 1){
if (p[i] != p[j]) return 0;
res[j].assign(n, 0);
res[j][i] = 1;
res[i][j] = 1;
}
}
}
for (int i = 0; i < n; ++i) {
if (!inc[i]) continue;
int ft = -1, lt = -1, bt = -1, at = -1;
for (int j = 0; j < n; ++j) {
if (p[i][j] == 2 && inc[j]){
if (ft == -1) ft = j;
if (j < i) bt = j;
if (j > i && at == -1) at = j;
lt = j;
}
}
if (lt == -1) continue;
if (at == -1) at = ft;
if (bt == -1) bt = lt;
res[i][bt] = 1;
res[i][at] = 1;
}
build(res);
return 1;
}
Compilation message
supertrees.cpp: In instantiation of 'bool operator==(std::vector<T>&, std::vector<T>&) [with T = int]':
supertrees.cpp:18:15: required from 'bool operator!=(std::vector<T>&, std::vector<T>&) [with T = int]'
supertrees.cpp:64:32: required from here
supertrees.cpp:10:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
10 | for (int i = 0; i < a.size(); ++i) {
| ~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 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 |
139 ms |
22448 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 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 |
139 ms |
22448 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
6 ms |
1108 KB |
Output is correct |
13 |
Correct |
138 ms |
22212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
3 ms |
596 KB |
Output is correct |
17 |
Correct |
72 ms |
8308 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
34 ms |
5852 KB |
Output is correct |
21 |
Correct |
136 ms |
22092 KB |
Output is correct |
22 |
Correct |
144 ms |
22060 KB |
Output is correct |
23 |
Correct |
140 ms |
22056 KB |
Output is correct |
24 |
Correct |
136 ms |
22048 KB |
Output is correct |
25 |
Correct |
58 ms |
8204 KB |
Output is correct |
26 |
Correct |
57 ms |
8316 KB |
Output is correct |
27 |
Correct |
140 ms |
22092 KB |
Output is correct |
28 |
Correct |
136 ms |
22088 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Incorrect |
0 ms |
212 KB |
Answer gives possible 1 while actual possible 0 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
35 ms |
5800 KB |
Output is correct |
5 |
Correct |
152 ms |
22276 KB |
Output is correct |
6 |
Correct |
177 ms |
22240 KB |
Output is correct |
7 |
Correct |
141 ms |
22272 KB |
Output is correct |
8 |
Correct |
1 ms |
256 KB |
Output is correct |
9 |
Correct |
35 ms |
5836 KB |
Output is correct |
10 |
Correct |
141 ms |
22256 KB |
Output is correct |
11 |
Correct |
141 ms |
22256 KB |
Output is correct |
12 |
Correct |
144 ms |
22244 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
35 ms |
5896 KB |
Output is correct |
17 |
Correct |
142 ms |
22596 KB |
Output is correct |
18 |
Correct |
140 ms |
22436 KB |
Output is correct |
19 |
Correct |
139 ms |
22432 KB |
Output is correct |
20 |
Correct |
140 ms |
22552 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 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 |
139 ms |
22448 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
6 ms |
1108 KB |
Output is correct |
13 |
Correct |
138 ms |
22212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
3 ms |
596 KB |
Output is correct |
17 |
Correct |
72 ms |
8308 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
34 ms |
5852 KB |
Output is correct |
21 |
Correct |
136 ms |
22092 KB |
Output is correct |
22 |
Correct |
144 ms |
22060 KB |
Output is correct |
23 |
Correct |
140 ms |
22056 KB |
Output is correct |
24 |
Correct |
136 ms |
22048 KB |
Output is correct |
25 |
Correct |
58 ms |
8204 KB |
Output is correct |
26 |
Correct |
57 ms |
8316 KB |
Output is correct |
27 |
Correct |
140 ms |
22092 KB |
Output is correct |
28 |
Correct |
136 ms |
22088 KB |
Output is correct |
29 |
Correct |
0 ms |
212 KB |
Output is correct |
30 |
Correct |
0 ms |
212 KB |
Output is correct |
31 |
Correct |
0 ms |
212 KB |
Output is correct |
32 |
Incorrect |
0 ms |
212 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 |
0 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 |
139 ms |
22448 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
6 ms |
1108 KB |
Output is correct |
13 |
Correct |
138 ms |
22212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
3 ms |
596 KB |
Output is correct |
17 |
Correct |
72 ms |
8308 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
34 ms |
5852 KB |
Output is correct |
21 |
Correct |
136 ms |
22092 KB |
Output is correct |
22 |
Correct |
144 ms |
22060 KB |
Output is correct |
23 |
Correct |
140 ms |
22056 KB |
Output is correct |
24 |
Correct |
136 ms |
22048 KB |
Output is correct |
25 |
Correct |
58 ms |
8204 KB |
Output is correct |
26 |
Correct |
57 ms |
8316 KB |
Output is correct |
27 |
Correct |
140 ms |
22092 KB |
Output is correct |
28 |
Correct |
136 ms |
22088 KB |
Output is correct |
29 |
Correct |
0 ms |
212 KB |
Output is correct |
30 |
Correct |
0 ms |
212 KB |
Output is correct |
31 |
Correct |
0 ms |
212 KB |
Output is correct |
32 |
Incorrect |
0 ms |
212 KB |
Answer gives possible 1 while actual possible 0 |
33 |
Halted |
0 ms |
0 KB |
- |