#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;
int construct(std::vector<std::vector<int>> p) {
int n = p.size();
vector<vector<int>> comp(n);
for(int i = 0;i<n;i++){
for(int j = 0;j<n;j++){
if(p[i][j]){
comp[i].push_back(j);
}
}
}
for(int i = 0;i<n;i++){
for(int j = 0;j<n;j++){
if(p[i][j] && comp[i] != comp[j]) return 0;
if(p[i][j] == 3) return 0;
}
}
vector<bool> vis(n,0);
vector<vector<int>> ans(n,vector<int>(n,0));
vector<int> roots;
for(int i = 0;i<n;i++){
if(!vis[i]){
roots.push_back(i);
for(int j = 0;j<(int)comp[i].size();j++){
if(comp[i][j] == i || p[i][comp[i][j]] != 1) continue;
ans[i][comp[i][j]] = 1;
ans[comp[i][j]][i] = 1;
vis[comp[i][j]] = 1;
}
}
}
vis.clear();
for(int i = 0;i<(int)roots.size();i++){
if(!vis[roots[i]]){
vector<int> x; x.push_back(roots[i]);
for(int j = 0;j<(int)roots.size();j++){
if(find(comp[roots[i]].begin(),comp[roots[i]].end(),roots[j]) != comp[roots[i]].end() && p[roots[i]][roots[j]] == 2){
x.push_back(roots[j]);
vis[roots[j]] = 1;
}
}
if(x.size() == 2) return 0;
for(int j = 0;j<(int)x.size();j++){
if(j == (int)x.size()-1) {
if(x[j] == x[0]) continue;
ans[x[j]][x[0]] = 1;
ans[x[0]][x[j]] = 1;
}else{
if(x[j] == x[j+1]) continue;
ans[x[j]][x[j+1]] = 1;
ans[x[j+1]][x[j]] = 1;
}
}
}
}
build(ans);
return 1;
}
# |
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 |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
300 KB |
Output is correct |
6 |
Correct |
9 ms |
1452 KB |
Output is correct |
7 |
Correct |
287 ms |
26456 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 |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
300 KB |
Output is correct |
6 |
Correct |
9 ms |
1452 KB |
Output is correct |
7 |
Correct |
287 ms |
26456 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 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 |
8 ms |
1244 KB |
Output is correct |
13 |
Correct |
176 ms |
22276 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
4 ms |
724 KB |
Output is correct |
17 |
Correct |
86 ms |
10920 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
47 ms |
6020 KB |
Output is correct |
21 |
Correct |
172 ms |
22836 KB |
Output is correct |
22 |
Correct |
188 ms |
22324 KB |
Output is correct |
23 |
Correct |
207 ms |
24268 KB |
Output is correct |
24 |
Correct |
170 ms |
22428 KB |
Output is correct |
25 |
Correct |
72 ms |
8908 KB |
Output is correct |
26 |
Correct |
71 ms |
8468 KB |
Output is correct |
27 |
Correct |
215 ms |
25316 KB |
Output is correct |
28 |
Correct |
170 ms |
22348 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 |
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 |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
10 ms |
1236 KB |
Output is correct |
9 |
Correct |
185 ms |
22856 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
296 KB |
Output is correct |
12 |
Correct |
9 ms |
1448 KB |
Output is correct |
13 |
Correct |
275 ms |
26812 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
296 KB |
Output is correct |
16 |
Correct |
4 ms |
724 KB |
Output is correct |
17 |
Correct |
85 ms |
11724 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
43 ms |
6284 KB |
Output is correct |
22 |
Correct |
178 ms |
23288 KB |
Output is correct |
23 |
Correct |
174 ms |
22860 KB |
Output is correct |
24 |
Correct |
219 ms |
25916 KB |
Output is correct |
25 |
Correct |
82 ms |
13260 KB |
Output is correct |
26 |
Correct |
75 ms |
9804 KB |
Output is correct |
27 |
Correct |
175 ms |
22920 KB |
Output is correct |
28 |
Correct |
230 ms |
24840 KB |
Output is correct |
29 |
Correct |
80 ms |
13372 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
300 KB |
Output is correct |
2 |
Correct |
1 ms |
296 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
43 ms |
5884 KB |
Output is correct |
5 |
Correct |
180 ms |
22608 KB |
Output is correct |
6 |
Correct |
176 ms |
22172 KB |
Output is correct |
7 |
Correct |
212 ms |
24196 KB |
Output is correct |
8 |
Correct |
1 ms |
296 KB |
Output is correct |
9 |
Correct |
44 ms |
5908 KB |
Output is correct |
10 |
Correct |
175 ms |
22652 KB |
Output is correct |
11 |
Correct |
172 ms |
22164 KB |
Output is correct |
12 |
Correct |
210 ms |
25376 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
296 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
47 ms |
5912 KB |
Output is correct |
17 |
Correct |
171 ms |
22724 KB |
Output is correct |
18 |
Correct |
177 ms |
22752 KB |
Output is correct |
19 |
Correct |
171 ms |
22500 KB |
Output is correct |
20 |
Correct |
170 ms |
22280 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 |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
300 KB |
Output is correct |
6 |
Correct |
9 ms |
1452 KB |
Output is correct |
7 |
Correct |
287 ms |
26456 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 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 |
8 ms |
1244 KB |
Output is correct |
13 |
Correct |
176 ms |
22276 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
4 ms |
724 KB |
Output is correct |
17 |
Correct |
86 ms |
10920 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
47 ms |
6020 KB |
Output is correct |
21 |
Correct |
172 ms |
22836 KB |
Output is correct |
22 |
Correct |
188 ms |
22324 KB |
Output is correct |
23 |
Correct |
207 ms |
24268 KB |
Output is correct |
24 |
Correct |
170 ms |
22428 KB |
Output is correct |
25 |
Correct |
72 ms |
8908 KB |
Output is correct |
26 |
Correct |
71 ms |
8468 KB |
Output is correct |
27 |
Correct |
215 ms |
25316 KB |
Output is correct |
28 |
Correct |
170 ms |
22348 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 |
212 KB |
Output is correct |
32 |
Correct |
1 ms |
212 KB |
Output is correct |
33 |
Correct |
0 ms |
212 KB |
Output is correct |
34 |
Correct |
1 ms |
212 KB |
Output is correct |
35 |
Correct |
0 ms |
212 KB |
Output is correct |
36 |
Correct |
10 ms |
1236 KB |
Output is correct |
37 |
Correct |
185 ms |
22856 KB |
Output is correct |
38 |
Correct |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
1 ms |
296 KB |
Output is correct |
40 |
Correct |
9 ms |
1448 KB |
Output is correct |
41 |
Correct |
275 ms |
26812 KB |
Output is correct |
42 |
Correct |
1 ms |
212 KB |
Output is correct |
43 |
Correct |
1 ms |
296 KB |
Output is correct |
44 |
Correct |
4 ms |
724 KB |
Output is correct |
45 |
Correct |
85 ms |
11724 KB |
Output is correct |
46 |
Correct |
1 ms |
212 KB |
Output is correct |
47 |
Correct |
1 ms |
212 KB |
Output is correct |
48 |
Correct |
1 ms |
212 KB |
Output is correct |
49 |
Correct |
43 ms |
6284 KB |
Output is correct |
50 |
Correct |
178 ms |
23288 KB |
Output is correct |
51 |
Correct |
174 ms |
22860 KB |
Output is correct |
52 |
Correct |
219 ms |
25916 KB |
Output is correct |
53 |
Correct |
82 ms |
13260 KB |
Output is correct |
54 |
Correct |
75 ms |
9804 KB |
Output is correct |
55 |
Correct |
175 ms |
22920 KB |
Output is correct |
56 |
Correct |
230 ms |
24840 KB |
Output is correct |
57 |
Correct |
80 ms |
13372 KB |
Output is correct |
58 |
Correct |
1 ms |
212 KB |
Output is correct |
59 |
Correct |
1 ms |
212 KB |
Output is correct |
60 |
Correct |
5 ms |
828 KB |
Output is correct |
61 |
Correct |
83 ms |
14120 KB |
Output is correct |
62 |
Correct |
1 ms |
212 KB |
Output is correct |
63 |
Correct |
1 ms |
212 KB |
Output is correct |
64 |
Correct |
0 ms |
212 KB |
Output is correct |
65 |
Correct |
43 ms |
6232 KB |
Output is correct |
66 |
Correct |
76 ms |
10664 KB |
Output is correct |
67 |
Correct |
74 ms |
10636 KB |
Output is correct |
68 |
Correct |
73 ms |
10364 KB |
Output is correct |
69 |
Correct |
77 ms |
14148 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 |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
300 KB |
Output is correct |
6 |
Correct |
9 ms |
1452 KB |
Output is correct |
7 |
Correct |
287 ms |
26456 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 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 |
8 ms |
1244 KB |
Output is correct |
13 |
Correct |
176 ms |
22276 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
4 ms |
724 KB |
Output is correct |
17 |
Correct |
86 ms |
10920 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
47 ms |
6020 KB |
Output is correct |
21 |
Correct |
172 ms |
22836 KB |
Output is correct |
22 |
Correct |
188 ms |
22324 KB |
Output is correct |
23 |
Correct |
207 ms |
24268 KB |
Output is correct |
24 |
Correct |
170 ms |
22428 KB |
Output is correct |
25 |
Correct |
72 ms |
8908 KB |
Output is correct |
26 |
Correct |
71 ms |
8468 KB |
Output is correct |
27 |
Correct |
215 ms |
25316 KB |
Output is correct |
28 |
Correct |
170 ms |
22348 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 |
212 KB |
Output is correct |
32 |
Correct |
1 ms |
212 KB |
Output is correct |
33 |
Correct |
0 ms |
212 KB |
Output is correct |
34 |
Correct |
1 ms |
212 KB |
Output is correct |
35 |
Correct |
0 ms |
212 KB |
Output is correct |
36 |
Correct |
10 ms |
1236 KB |
Output is correct |
37 |
Correct |
185 ms |
22856 KB |
Output is correct |
38 |
Correct |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
1 ms |
296 KB |
Output is correct |
40 |
Correct |
9 ms |
1448 KB |
Output is correct |
41 |
Correct |
275 ms |
26812 KB |
Output is correct |
42 |
Correct |
1 ms |
212 KB |
Output is correct |
43 |
Correct |
1 ms |
296 KB |
Output is correct |
44 |
Correct |
4 ms |
724 KB |
Output is correct |
45 |
Correct |
85 ms |
11724 KB |
Output is correct |
46 |
Correct |
1 ms |
212 KB |
Output is correct |
47 |
Correct |
1 ms |
212 KB |
Output is correct |
48 |
Correct |
1 ms |
212 KB |
Output is correct |
49 |
Correct |
43 ms |
6284 KB |
Output is correct |
50 |
Correct |
178 ms |
23288 KB |
Output is correct |
51 |
Correct |
174 ms |
22860 KB |
Output is correct |
52 |
Correct |
219 ms |
25916 KB |
Output is correct |
53 |
Correct |
82 ms |
13260 KB |
Output is correct |
54 |
Correct |
75 ms |
9804 KB |
Output is correct |
55 |
Correct |
175 ms |
22920 KB |
Output is correct |
56 |
Correct |
230 ms |
24840 KB |
Output is correct |
57 |
Correct |
80 ms |
13372 KB |
Output is correct |
58 |
Correct |
1 ms |
300 KB |
Output is correct |
59 |
Correct |
1 ms |
296 KB |
Output is correct |
60 |
Correct |
0 ms |
212 KB |
Output is correct |
61 |
Correct |
43 ms |
5884 KB |
Output is correct |
62 |
Correct |
180 ms |
22608 KB |
Output is correct |
63 |
Correct |
176 ms |
22172 KB |
Output is correct |
64 |
Correct |
212 ms |
24196 KB |
Output is correct |
65 |
Correct |
1 ms |
296 KB |
Output is correct |
66 |
Correct |
44 ms |
5908 KB |
Output is correct |
67 |
Correct |
175 ms |
22652 KB |
Output is correct |
68 |
Correct |
172 ms |
22164 KB |
Output is correct |
69 |
Correct |
210 ms |
25376 KB |
Output is correct |
70 |
Correct |
1 ms |
212 KB |
Output is correct |
71 |
Correct |
0 ms |
296 KB |
Output is correct |
72 |
Correct |
1 ms |
212 KB |
Output is correct |
73 |
Correct |
47 ms |
5912 KB |
Output is correct |
74 |
Correct |
171 ms |
22724 KB |
Output is correct |
75 |
Correct |
177 ms |
22752 KB |
Output is correct |
76 |
Correct |
171 ms |
22500 KB |
Output is correct |
77 |
Correct |
170 ms |
22280 KB |
Output is correct |
78 |
Correct |
1 ms |
212 KB |
Output is correct |
79 |
Correct |
1 ms |
212 KB |
Output is correct |
80 |
Correct |
5 ms |
828 KB |
Output is correct |
81 |
Correct |
83 ms |
14120 KB |
Output is correct |
82 |
Correct |
1 ms |
212 KB |
Output is correct |
83 |
Correct |
1 ms |
212 KB |
Output is correct |
84 |
Correct |
0 ms |
212 KB |
Output is correct |
85 |
Correct |
43 ms |
6232 KB |
Output is correct |
86 |
Correct |
76 ms |
10664 KB |
Output is correct |
87 |
Correct |
74 ms |
10636 KB |
Output is correct |
88 |
Correct |
73 ms |
10364 KB |
Output is correct |
89 |
Correct |
77 ms |
14148 KB |
Output is correct |
90 |
Correct |
1 ms |
300 KB |
Output is correct |
91 |
Correct |
1 ms |
296 KB |
Output is correct |
92 |
Correct |
4 ms |
852 KB |
Output is correct |
93 |
Correct |
84 ms |
14064 KB |
Output is correct |
94 |
Correct |
1 ms |
304 KB |
Output is correct |
95 |
Correct |
1 ms |
212 KB |
Output is correct |
96 |
Correct |
1 ms |
212 KB |
Output is correct |
97 |
Correct |
18 ms |
2808 KB |
Output is correct |
98 |
Correct |
78 ms |
10612 KB |
Output is correct |
99 |
Correct |
74 ms |
10608 KB |
Output is correct |
100 |
Correct |
77 ms |
10356 KB |
Output is correct |
101 |
Correct |
75 ms |
10096 KB |
Output is correct |
102 |
Correct |
74 ms |
14068 KB |
Output is correct |
103 |
Correct |
74 ms |
14076 KB |
Output is correct |
104 |
Correct |
76 ms |
14080 KB |
Output is correct |
105 |
Correct |
82 ms |
12592 KB |
Output is correct |