#include <bits/stdc++.h>
#include "supertrees.h"
using namespace std;
#define ll long long
#define endl "\n"
const int MOD = 998244353;
/*
int n2;
std::vector<std::vector<int>> p;
std::vector<std::vector<int>> b;
bool called = false;
static void check(bool cond, std::string message) {
if (!cond) {
cout << message << endl;
exit(0);
}
}
void build(std::vector<std::vector<int>> _b) {
check(!called, "build is called more than once");
called = true;
check((int)_b.size() == n2, "Invalid number of rows in b");
for (int i = 0; i < n2; i++) {
check((int)_b[i].size() == n2, "Invalid number of columns in b");
}
b = _b;
}*/
void DFS(int x, vector<int>& num, int curr, int type, vector<vector<int>>& edges){
if(curr == (int)num.size() - 1){
if(type == 1) return;
else{
edges[num[curr]][x] = 1;
edges[x][num[curr]] = 1;
return;
}
}
edges[num[curr]][num[curr + 1]] = 1;
edges[num[curr + 1]][num[curr]] = 1;
DFS(x, num, curr + 1, type, edges);
}
int construct(vector<vector<int>> v){
int n = (int)v[0].size();
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
if(v[i][j] == 3) return 0;
}
}
vector<bool> done(n, 0);
vector<vector<int>> edges(n, vector<int> (n, 0));
for(int i = 0; i < n; i++){
if(done[i]) continue;
vector<int> two;
vector<int> one = {i};
set<int> cc;
cc.insert(i);
done[i] = 1;
for(int j = 0; j < n; j++){
if(i == j) continue;
if(v[i][j] == 1) {one.push_back(j); cc.insert(j);}
else if(v[i][j] == 2) {two.push_back(j); cc.insert(j);}
}
for(int x : two){
done[x] = 1;
for(int j = 0; j < n; j++){
if(x == j) continue;
bool good = cc.count(j);
if(good == false && v[x][j] > 0) return 0;
if(good == true && v[x][j] == 0) return 0;
}
}
for(int x : one){
done[x] = 1;
for(int j = 0; j < n; j++){
if(x == j) continue;
bool good = cc.count(j);
if(good == false && v[x][j] > 0) return 0;
if(good == true && v[x][j] != max(v[i][j], v[i][x])) return 0;
}
}
if(two.size() == 0){
DFS(i, one, 0, 1, edges);
}else{
vector<vector<int>> circle;
circle.push_back(one);
vector<bool> assigned(two.size(), 0);
for(int j = 0; j < two.size(); j++){
if(assigned[j]) continue;
assigned[j] = 1;
one.resize(0);
one.push_back(two[j]);
for(int q = 0; q < two.size(); q++){
if(q == j) continue;
if(v[two[j]][two[q]] == 1){
if(assigned[q]) return 0;
assigned[q] = 1;
one.push_back(two[q]);
}
}
circle.push_back(one);
}
if((int)circle.size() < 3) return 0;
for(auto t : circle){
DFS(i, t, 0, 1, edges);
}
int sz = (int)circle.size();
for(int j = 0; j < sz; j++){
edges[circle[j][0]][circle[(j + 1) % sz][0]] = 1;
edges[circle[(j + 1) % sz][0]][circle[j][0]] = 1;
}
}
}
build(edges);
return 1;
}
/*
int main() {
cin >> n2;
p.resize(n2);
for (int i = 0; i < n2; i++) {
p[i].resize(n2);
}
for (int i = 0; i < n2; i++) {
for (int j = 0; j < n2; j++) {
cin >> p[i][j];
}
}
int possible = construct(p);
check(possible == 0 || possible == 1, "Invalid return value of construct");
if (possible == 1) {
check(called, "construct returned 1 without calling build");
} else {
check(!called, "construct called build but returned 0");
}
cout << possible << endl;
if (possible == 1) {
for (int i = 0; i < n2; i++) {
for (int j = 0; j < n2; j++) {
if (j) {
cout << " ";
}
cout << b[i][j];
}
printf("\n");
}
}
}*/
Compilation message
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:92:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
92 | for(int j = 0; j < two.size(); j++){
| ~~^~~~~~~~~~~~
supertrees.cpp:97:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
97 | for(int q = 0; q < two.size(); q++){
| ~~^~~~~~~~~~~~
# |
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 |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
8 ms |
1108 KB |
Output is correct |
7 |
Correct |
213 ms |
22020 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 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
8 ms |
1108 KB |
Output is correct |
7 |
Correct |
213 ms |
22020 KB |
Output is correct |
8 |
Correct |
0 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 |
8 ms |
1108 KB |
Output is correct |
13 |
Correct |
183 ms |
22020 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
4 ms |
724 KB |
Output is correct |
17 |
Correct |
79 ms |
12220 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
50 ms |
5756 KB |
Output is correct |
21 |
Correct |
209 ms |
22092 KB |
Output is correct |
22 |
Correct |
174 ms |
22032 KB |
Output is correct |
23 |
Correct |
229 ms |
22028 KB |
Output is correct |
24 |
Correct |
181 ms |
22020 KB |
Output is correct |
25 |
Correct |
74 ms |
12048 KB |
Output is correct |
26 |
Correct |
108 ms |
12044 KB |
Output is correct |
27 |
Correct |
206 ms |
22032 KB |
Output is correct |
28 |
Correct |
174 ms |
22040 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 |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
8 ms |
1148 KB |
Output is correct |
9 |
Correct |
179 ms |
21964 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
11 ms |
1108 KB |
Output is correct |
13 |
Correct |
208 ms |
22016 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
6 ms |
712 KB |
Output is correct |
17 |
Correct |
79 ms |
12172 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
67 ms |
5708 KB |
Output is correct |
22 |
Correct |
184 ms |
22032 KB |
Output is correct |
23 |
Correct |
177 ms |
22012 KB |
Output is correct |
24 |
Correct |
201 ms |
22024 KB |
Output is correct |
25 |
Correct |
70 ms |
12080 KB |
Output is correct |
26 |
Correct |
69 ms |
12032 KB |
Output is correct |
27 |
Correct |
172 ms |
21964 KB |
Output is correct |
28 |
Correct |
225 ms |
22092 KB |
Output is correct |
29 |
Correct |
70 ms |
12044 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
51 ms |
5696 KB |
Output is correct |
5 |
Correct |
197 ms |
22036 KB |
Output is correct |
6 |
Correct |
186 ms |
22068 KB |
Output is correct |
7 |
Correct |
208 ms |
22028 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
59 ms |
5708 KB |
Output is correct |
10 |
Correct |
225 ms |
22000 KB |
Output is correct |
11 |
Correct |
178 ms |
22028 KB |
Output is correct |
12 |
Correct |
225 ms |
22124 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 |
60 ms |
5768 KB |
Output is correct |
17 |
Correct |
197 ms |
22020 KB |
Output is correct |
18 |
Correct |
182 ms |
22028 KB |
Output is correct |
19 |
Correct |
199 ms |
22092 KB |
Output is correct |
20 |
Correct |
179 ms |
21996 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 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
8 ms |
1108 KB |
Output is correct |
7 |
Correct |
213 ms |
22020 KB |
Output is correct |
8 |
Correct |
0 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 |
8 ms |
1108 KB |
Output is correct |
13 |
Correct |
183 ms |
22020 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
4 ms |
724 KB |
Output is correct |
17 |
Correct |
79 ms |
12220 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
50 ms |
5756 KB |
Output is correct |
21 |
Correct |
209 ms |
22092 KB |
Output is correct |
22 |
Correct |
174 ms |
22032 KB |
Output is correct |
23 |
Correct |
229 ms |
22028 KB |
Output is correct |
24 |
Correct |
181 ms |
22020 KB |
Output is correct |
25 |
Correct |
74 ms |
12048 KB |
Output is correct |
26 |
Correct |
108 ms |
12044 KB |
Output is correct |
27 |
Correct |
206 ms |
22032 KB |
Output is correct |
28 |
Correct |
174 ms |
22040 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
1 ms |
212 KB |
Output is correct |
31 |
Correct |
0 ms |
212 KB |
Output is correct |
32 |
Correct |
0 ms |
212 KB |
Output is correct |
33 |
Correct |
1 ms |
212 KB |
Output is correct |
34 |
Correct |
0 ms |
212 KB |
Output is correct |
35 |
Correct |
0 ms |
212 KB |
Output is correct |
36 |
Correct |
8 ms |
1148 KB |
Output is correct |
37 |
Correct |
179 ms |
21964 KB |
Output is correct |
38 |
Correct |
0 ms |
212 KB |
Output is correct |
39 |
Correct |
1 ms |
212 KB |
Output is correct |
40 |
Correct |
11 ms |
1108 KB |
Output is correct |
41 |
Correct |
208 ms |
22016 KB |
Output is correct |
42 |
Correct |
0 ms |
212 KB |
Output is correct |
43 |
Correct |
0 ms |
212 KB |
Output is correct |
44 |
Correct |
6 ms |
712 KB |
Output is correct |
45 |
Correct |
79 ms |
12172 KB |
Output is correct |
46 |
Correct |
1 ms |
212 KB |
Output is correct |
47 |
Correct |
0 ms |
212 KB |
Output is correct |
48 |
Correct |
0 ms |
212 KB |
Output is correct |
49 |
Correct |
67 ms |
5708 KB |
Output is correct |
50 |
Correct |
184 ms |
22032 KB |
Output is correct |
51 |
Correct |
177 ms |
22012 KB |
Output is correct |
52 |
Correct |
201 ms |
22024 KB |
Output is correct |
53 |
Correct |
70 ms |
12080 KB |
Output is correct |
54 |
Correct |
69 ms |
12032 KB |
Output is correct |
55 |
Correct |
172 ms |
21964 KB |
Output is correct |
56 |
Correct |
225 ms |
22092 KB |
Output is correct |
57 |
Correct |
70 ms |
12044 KB |
Output is correct |
58 |
Correct |
1 ms |
212 KB |
Output is correct |
59 |
Correct |
1 ms |
212 KB |
Output is correct |
60 |
Correct |
4 ms |
724 KB |
Output is correct |
61 |
Correct |
81 ms |
12048 KB |
Output is correct |
62 |
Correct |
1 ms |
212 KB |
Output is correct |
63 |
Correct |
1 ms |
212 KB |
Output is correct |
64 |
Correct |
1 ms |
212 KB |
Output is correct |
65 |
Correct |
49 ms |
5716 KB |
Output is correct |
66 |
Correct |
83 ms |
14068 KB |
Output is correct |
67 |
Correct |
79 ms |
14076 KB |
Output is correct |
68 |
Correct |
79 ms |
14068 KB |
Output is correct |
69 |
Correct |
78 ms |
14072 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 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
8 ms |
1108 KB |
Output is correct |
7 |
Correct |
213 ms |
22020 KB |
Output is correct |
8 |
Correct |
0 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 |
8 ms |
1108 KB |
Output is correct |
13 |
Correct |
183 ms |
22020 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
4 ms |
724 KB |
Output is correct |
17 |
Correct |
79 ms |
12220 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
50 ms |
5756 KB |
Output is correct |
21 |
Correct |
209 ms |
22092 KB |
Output is correct |
22 |
Correct |
174 ms |
22032 KB |
Output is correct |
23 |
Correct |
229 ms |
22028 KB |
Output is correct |
24 |
Correct |
181 ms |
22020 KB |
Output is correct |
25 |
Correct |
74 ms |
12048 KB |
Output is correct |
26 |
Correct |
108 ms |
12044 KB |
Output is correct |
27 |
Correct |
206 ms |
22032 KB |
Output is correct |
28 |
Correct |
174 ms |
22040 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
1 ms |
212 KB |
Output is correct |
31 |
Correct |
0 ms |
212 KB |
Output is correct |
32 |
Correct |
0 ms |
212 KB |
Output is correct |
33 |
Correct |
1 ms |
212 KB |
Output is correct |
34 |
Correct |
0 ms |
212 KB |
Output is correct |
35 |
Correct |
0 ms |
212 KB |
Output is correct |
36 |
Correct |
8 ms |
1148 KB |
Output is correct |
37 |
Correct |
179 ms |
21964 KB |
Output is correct |
38 |
Correct |
0 ms |
212 KB |
Output is correct |
39 |
Correct |
1 ms |
212 KB |
Output is correct |
40 |
Correct |
11 ms |
1108 KB |
Output is correct |
41 |
Correct |
208 ms |
22016 KB |
Output is correct |
42 |
Correct |
0 ms |
212 KB |
Output is correct |
43 |
Correct |
0 ms |
212 KB |
Output is correct |
44 |
Correct |
6 ms |
712 KB |
Output is correct |
45 |
Correct |
79 ms |
12172 KB |
Output is correct |
46 |
Correct |
1 ms |
212 KB |
Output is correct |
47 |
Correct |
0 ms |
212 KB |
Output is correct |
48 |
Correct |
0 ms |
212 KB |
Output is correct |
49 |
Correct |
67 ms |
5708 KB |
Output is correct |
50 |
Correct |
184 ms |
22032 KB |
Output is correct |
51 |
Correct |
177 ms |
22012 KB |
Output is correct |
52 |
Correct |
201 ms |
22024 KB |
Output is correct |
53 |
Correct |
70 ms |
12080 KB |
Output is correct |
54 |
Correct |
69 ms |
12032 KB |
Output is correct |
55 |
Correct |
172 ms |
21964 KB |
Output is correct |
56 |
Correct |
225 ms |
22092 KB |
Output is correct |
57 |
Correct |
70 ms |
12044 KB |
Output is correct |
58 |
Correct |
0 ms |
212 KB |
Output is correct |
59 |
Correct |
1 ms |
212 KB |
Output is correct |
60 |
Correct |
1 ms |
212 KB |
Output is correct |
61 |
Correct |
51 ms |
5696 KB |
Output is correct |
62 |
Correct |
197 ms |
22036 KB |
Output is correct |
63 |
Correct |
186 ms |
22068 KB |
Output is correct |
64 |
Correct |
208 ms |
22028 KB |
Output is correct |
65 |
Correct |
0 ms |
212 KB |
Output is correct |
66 |
Correct |
59 ms |
5708 KB |
Output is correct |
67 |
Correct |
225 ms |
22000 KB |
Output is correct |
68 |
Correct |
178 ms |
22028 KB |
Output is correct |
69 |
Correct |
225 ms |
22124 KB |
Output is correct |
70 |
Correct |
0 ms |
212 KB |
Output is correct |
71 |
Correct |
0 ms |
212 KB |
Output is correct |
72 |
Correct |
0 ms |
212 KB |
Output is correct |
73 |
Correct |
60 ms |
5768 KB |
Output is correct |
74 |
Correct |
197 ms |
22020 KB |
Output is correct |
75 |
Correct |
182 ms |
22028 KB |
Output is correct |
76 |
Correct |
199 ms |
22092 KB |
Output is correct |
77 |
Correct |
179 ms |
21996 KB |
Output is correct |
78 |
Correct |
1 ms |
212 KB |
Output is correct |
79 |
Correct |
1 ms |
212 KB |
Output is correct |
80 |
Correct |
4 ms |
724 KB |
Output is correct |
81 |
Correct |
81 ms |
12048 KB |
Output is correct |
82 |
Correct |
1 ms |
212 KB |
Output is correct |
83 |
Correct |
1 ms |
212 KB |
Output is correct |
84 |
Correct |
1 ms |
212 KB |
Output is correct |
85 |
Correct |
49 ms |
5716 KB |
Output is correct |
86 |
Correct |
83 ms |
14068 KB |
Output is correct |
87 |
Correct |
79 ms |
14076 KB |
Output is correct |
88 |
Correct |
79 ms |
14068 KB |
Output is correct |
89 |
Correct |
78 ms |
14072 KB |
Output is correct |
90 |
Correct |
1 ms |
304 KB |
Output is correct |
91 |
Correct |
1 ms |
296 KB |
Output is correct |
92 |
Correct |
4 ms |
596 KB |
Output is correct |
93 |
Correct |
90 ms |
10108 KB |
Output is correct |
94 |
Correct |
1 ms |
212 KB |
Output is correct |
95 |
Correct |
1 ms |
304 KB |
Output is correct |
96 |
Correct |
1 ms |
296 KB |
Output is correct |
97 |
Correct |
19 ms |
2680 KB |
Output is correct |
98 |
Correct |
69 ms |
10108 KB |
Output is correct |
99 |
Correct |
93 ms |
10120 KB |
Output is correct |
100 |
Correct |
79 ms |
10112 KB |
Output is correct |
101 |
Correct |
72 ms |
10100 KB |
Output is correct |
102 |
Correct |
71 ms |
10100 KB |
Output is correct |
103 |
Correct |
73 ms |
10060 KB |
Output is correct |
104 |
Correct |
67 ms |
10104 KB |
Output is correct |
105 |
Correct |
89 ms |
10116 KB |
Output is correct |