#include "supertrees.h"
#include <vector>
#include <bits/stdc++.h>
using namespace std;
struct dsu{
int n;
vector<int> size, parent;
dsu(int _n) : n(_n), size(n, 1), parent(n){
iota(parent.begin(), parent.end(), 0);
}
int get(int a){
return a == parent[a] ? a : parent[a] = get(parent[a]);
}
bool unite(int b, int a){
a = get(a);
b = get(b);
if(a == b){
return 0;
}
size[b] += size[a];
parent[a] = b;
return 1;
}
};
int construct(vector<vector<int>> a){
int n = a.size();
vector<vector<int>> ans(n, vector<int>(n, 0));
vector<vector<int>> v1(n),v2(n);
for(int i = 0; i < n; i++){
for(int j = i + 1; j < n; j++){
if(a[i][j] == 1){
v1[i].push_back(j);
v1[j].push_back(i);
} else if(a[i][j] == 2){
v2[i].push_back(j);
v2[j].push_back(i);
} else if(a[i][j] == 3){
return 0;
}
}
}
dsu s(n);
for(int i = 0; i < n; i++){
if(s.parent[i] == i){
for(int j = 0; j < n; j++){
for(int k : v1[i]){
if(a[k][j] != a[i][j]){
return 0;
}
ans[i][k] = 1;
ans[k][i] = 1;
s.unite(i, k);
}
}
}
}
vector<bool> b(n, false);
for(int i = 0; i < n; i++){
if(b[s.parent[i]]){
continue;
}
b[i] = true;
int cur = i;
for(int j : v2[i]){
if(s.parent[j] != j){
if(a[i][s.parent[j]] != 2){
return 0;
}
continue;
}
for(int k : v2[j]){
if(a[i][k] == 0 || (a[i][k] == 1 && s.parent[k] != i) || (a[i][k] == 2 && s.parent[k] == i)){
return 0;
}
}
for(int k : v2[i]){
if(a[j][k] == 0 || (a[j][k] == 1 && s.parent[k] != j) || (a[j][k] == 2 && s.parent[k] == i)){
return 0;
}
}
ans[cur][j] = 1;
ans[j][cur] = 1;
b[j] = true;
cur = j;
}
if(cur == i){
continue;
}
if(ans[i][cur]){
return 0;
}
ans[i][cur] = 1;
ans[cur][i] = 1;
}
build(ans);
return 1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
296 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
8 ms |
1432 KB |
Output is correct |
7 |
Correct |
179 ms |
28068 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
296 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
8 ms |
1432 KB |
Output is correct |
7 |
Correct |
179 ms |
28068 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
10 ms |
1204 KB |
Output is correct |
13 |
Correct |
161 ms |
23956 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
4 ms |
936 KB |
Output is correct |
17 |
Correct |
104 ms |
16876 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
0 ms |
204 KB |
Output is correct |
20 |
Correct |
46 ms |
6304 KB |
Output is correct |
21 |
Correct |
169 ms |
24588 KB |
Output is correct |
22 |
Correct |
164 ms |
24004 KB |
Output is correct |
23 |
Correct |
183 ms |
26052 KB |
Output is correct |
24 |
Correct |
171 ms |
23976 KB |
Output is correct |
25 |
Correct |
75 ms |
14572 KB |
Output is correct |
26 |
Correct |
65 ms |
14148 KB |
Output is correct |
27 |
Correct |
176 ms |
27124 KB |
Output is correct |
28 |
Correct |
158 ms |
24008 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
292 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
7 ms |
1160 KB |
Output is correct |
9 |
Correct |
159 ms |
23976 KB |
Output is correct |
10 |
Correct |
1 ms |
288 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
7 ms |
1484 KB |
Output is correct |
13 |
Correct |
167 ms |
28072 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
0 ms |
204 KB |
Output is correct |
16 |
Correct |
4 ms |
972 KB |
Output is correct |
17 |
Correct |
84 ms |
17128 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
0 ms |
204 KB |
Output is correct |
20 |
Correct |
0 ms |
204 KB |
Output is correct |
21 |
Correct |
41 ms |
6312 KB |
Output is correct |
22 |
Correct |
161 ms |
24552 KB |
Output is correct |
23 |
Correct |
169 ms |
24044 KB |
Output is correct |
24 |
Correct |
173 ms |
27076 KB |
Output is correct |
25 |
Correct |
66 ms |
14148 KB |
Output is correct |
26 |
Correct |
70 ms |
14572 KB |
Output is correct |
27 |
Correct |
158 ms |
24004 KB |
Output is correct |
28 |
Correct |
169 ms |
26096 KB |
Output is correct |
29 |
Correct |
67 ms |
14068 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
292 KB |
Output is correct |
4 |
Correct |
42 ms |
6336 KB |
Output is correct |
5 |
Correct |
177 ms |
24516 KB |
Output is correct |
6 |
Correct |
159 ms |
24004 KB |
Output is correct |
7 |
Correct |
185 ms |
26156 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
40 ms |
6316 KB |
Output is correct |
10 |
Correct |
165 ms |
24484 KB |
Output is correct |
11 |
Correct |
158 ms |
24008 KB |
Output is correct |
12 |
Correct |
168 ms |
27172 KB |
Output is correct |
13 |
Correct |
0 ms |
204 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
0 ms |
204 KB |
Output is correct |
16 |
Correct |
41 ms |
6316 KB |
Output is correct |
17 |
Correct |
159 ms |
24548 KB |
Output is correct |
18 |
Correct |
163 ms |
24644 KB |
Output is correct |
19 |
Correct |
160 ms |
24172 KB |
Output is correct |
20 |
Correct |
158 ms |
24060 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
296 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
8 ms |
1432 KB |
Output is correct |
7 |
Correct |
179 ms |
28068 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
10 ms |
1204 KB |
Output is correct |
13 |
Correct |
161 ms |
23956 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
4 ms |
936 KB |
Output is correct |
17 |
Correct |
104 ms |
16876 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
0 ms |
204 KB |
Output is correct |
20 |
Correct |
46 ms |
6304 KB |
Output is correct |
21 |
Correct |
169 ms |
24588 KB |
Output is correct |
22 |
Correct |
164 ms |
24004 KB |
Output is correct |
23 |
Correct |
183 ms |
26052 KB |
Output is correct |
24 |
Correct |
171 ms |
23976 KB |
Output is correct |
25 |
Correct |
75 ms |
14572 KB |
Output is correct |
26 |
Correct |
65 ms |
14148 KB |
Output is correct |
27 |
Correct |
176 ms |
27124 KB |
Output is correct |
28 |
Correct |
158 ms |
24008 KB |
Output is correct |
29 |
Correct |
0 ms |
292 KB |
Output is correct |
30 |
Correct |
1 ms |
332 KB |
Output is correct |
31 |
Correct |
0 ms |
204 KB |
Output is correct |
32 |
Correct |
0 ms |
204 KB |
Output is correct |
33 |
Correct |
0 ms |
204 KB |
Output is correct |
34 |
Correct |
0 ms |
204 KB |
Output is correct |
35 |
Correct |
0 ms |
204 KB |
Output is correct |
36 |
Correct |
7 ms |
1160 KB |
Output is correct |
37 |
Correct |
159 ms |
23976 KB |
Output is correct |
38 |
Correct |
1 ms |
288 KB |
Output is correct |
39 |
Correct |
0 ms |
204 KB |
Output is correct |
40 |
Correct |
7 ms |
1484 KB |
Output is correct |
41 |
Correct |
167 ms |
28072 KB |
Output is correct |
42 |
Correct |
0 ms |
204 KB |
Output is correct |
43 |
Correct |
0 ms |
204 KB |
Output is correct |
44 |
Correct |
4 ms |
972 KB |
Output is correct |
45 |
Correct |
84 ms |
17128 KB |
Output is correct |
46 |
Correct |
1 ms |
204 KB |
Output is correct |
47 |
Correct |
0 ms |
204 KB |
Output is correct |
48 |
Correct |
0 ms |
204 KB |
Output is correct |
49 |
Correct |
41 ms |
6312 KB |
Output is correct |
50 |
Correct |
161 ms |
24552 KB |
Output is correct |
51 |
Correct |
169 ms |
24044 KB |
Output is correct |
52 |
Correct |
173 ms |
27076 KB |
Output is correct |
53 |
Correct |
66 ms |
14148 KB |
Output is correct |
54 |
Correct |
70 ms |
14572 KB |
Output is correct |
55 |
Correct |
158 ms |
24004 KB |
Output is correct |
56 |
Correct |
169 ms |
26096 KB |
Output is correct |
57 |
Correct |
67 ms |
14068 KB |
Output is correct |
58 |
Correct |
0 ms |
204 KB |
Output is correct |
59 |
Correct |
0 ms |
296 KB |
Output is correct |
60 |
Correct |
4 ms |
1044 KB |
Output is correct |
61 |
Correct |
87 ms |
18724 KB |
Output is correct |
62 |
Correct |
0 ms |
204 KB |
Output is correct |
63 |
Correct |
0 ms |
204 KB |
Output is correct |
64 |
Correct |
0 ms |
204 KB |
Output is correct |
65 |
Correct |
43 ms |
6256 KB |
Output is correct |
66 |
Correct |
68 ms |
14636 KB |
Output is correct |
67 |
Correct |
69 ms |
14700 KB |
Output is correct |
68 |
Correct |
70 ms |
14328 KB |
Output is correct |
69 |
Correct |
77 ms |
14060 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
296 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
8 ms |
1432 KB |
Output is correct |
7 |
Correct |
179 ms |
28068 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
10 ms |
1204 KB |
Output is correct |
13 |
Correct |
161 ms |
23956 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
4 ms |
936 KB |
Output is correct |
17 |
Correct |
104 ms |
16876 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
0 ms |
204 KB |
Output is correct |
20 |
Correct |
46 ms |
6304 KB |
Output is correct |
21 |
Correct |
169 ms |
24588 KB |
Output is correct |
22 |
Correct |
164 ms |
24004 KB |
Output is correct |
23 |
Correct |
183 ms |
26052 KB |
Output is correct |
24 |
Correct |
171 ms |
23976 KB |
Output is correct |
25 |
Correct |
75 ms |
14572 KB |
Output is correct |
26 |
Correct |
65 ms |
14148 KB |
Output is correct |
27 |
Correct |
176 ms |
27124 KB |
Output is correct |
28 |
Correct |
158 ms |
24008 KB |
Output is correct |
29 |
Correct |
0 ms |
292 KB |
Output is correct |
30 |
Correct |
1 ms |
332 KB |
Output is correct |
31 |
Correct |
0 ms |
204 KB |
Output is correct |
32 |
Correct |
0 ms |
204 KB |
Output is correct |
33 |
Correct |
0 ms |
204 KB |
Output is correct |
34 |
Correct |
0 ms |
204 KB |
Output is correct |
35 |
Correct |
0 ms |
204 KB |
Output is correct |
36 |
Correct |
7 ms |
1160 KB |
Output is correct |
37 |
Correct |
159 ms |
23976 KB |
Output is correct |
38 |
Correct |
1 ms |
288 KB |
Output is correct |
39 |
Correct |
0 ms |
204 KB |
Output is correct |
40 |
Correct |
7 ms |
1484 KB |
Output is correct |
41 |
Correct |
167 ms |
28072 KB |
Output is correct |
42 |
Correct |
0 ms |
204 KB |
Output is correct |
43 |
Correct |
0 ms |
204 KB |
Output is correct |
44 |
Correct |
4 ms |
972 KB |
Output is correct |
45 |
Correct |
84 ms |
17128 KB |
Output is correct |
46 |
Correct |
1 ms |
204 KB |
Output is correct |
47 |
Correct |
0 ms |
204 KB |
Output is correct |
48 |
Correct |
0 ms |
204 KB |
Output is correct |
49 |
Correct |
41 ms |
6312 KB |
Output is correct |
50 |
Correct |
161 ms |
24552 KB |
Output is correct |
51 |
Correct |
169 ms |
24044 KB |
Output is correct |
52 |
Correct |
173 ms |
27076 KB |
Output is correct |
53 |
Correct |
66 ms |
14148 KB |
Output is correct |
54 |
Correct |
70 ms |
14572 KB |
Output is correct |
55 |
Correct |
158 ms |
24004 KB |
Output is correct |
56 |
Correct |
169 ms |
26096 KB |
Output is correct |
57 |
Correct |
67 ms |
14068 KB |
Output is correct |
58 |
Correct |
0 ms |
204 KB |
Output is correct |
59 |
Correct |
1 ms |
204 KB |
Output is correct |
60 |
Correct |
1 ms |
292 KB |
Output is correct |
61 |
Correct |
42 ms |
6336 KB |
Output is correct |
62 |
Correct |
177 ms |
24516 KB |
Output is correct |
63 |
Correct |
159 ms |
24004 KB |
Output is correct |
64 |
Correct |
185 ms |
26156 KB |
Output is correct |
65 |
Correct |
0 ms |
204 KB |
Output is correct |
66 |
Correct |
40 ms |
6316 KB |
Output is correct |
67 |
Correct |
165 ms |
24484 KB |
Output is correct |
68 |
Correct |
158 ms |
24008 KB |
Output is correct |
69 |
Correct |
168 ms |
27172 KB |
Output is correct |
70 |
Correct |
0 ms |
204 KB |
Output is correct |
71 |
Correct |
0 ms |
204 KB |
Output is correct |
72 |
Correct |
0 ms |
204 KB |
Output is correct |
73 |
Correct |
41 ms |
6316 KB |
Output is correct |
74 |
Correct |
159 ms |
24548 KB |
Output is correct |
75 |
Correct |
163 ms |
24644 KB |
Output is correct |
76 |
Correct |
160 ms |
24172 KB |
Output is correct |
77 |
Correct |
158 ms |
24060 KB |
Output is correct |
78 |
Correct |
0 ms |
204 KB |
Output is correct |
79 |
Correct |
0 ms |
296 KB |
Output is correct |
80 |
Correct |
4 ms |
1044 KB |
Output is correct |
81 |
Correct |
87 ms |
18724 KB |
Output is correct |
82 |
Correct |
0 ms |
204 KB |
Output is correct |
83 |
Correct |
0 ms |
204 KB |
Output is correct |
84 |
Correct |
0 ms |
204 KB |
Output is correct |
85 |
Correct |
43 ms |
6256 KB |
Output is correct |
86 |
Correct |
68 ms |
14636 KB |
Output is correct |
87 |
Correct |
69 ms |
14700 KB |
Output is correct |
88 |
Correct |
70 ms |
14328 KB |
Output is correct |
89 |
Correct |
77 ms |
14060 KB |
Output is correct |
90 |
Correct |
0 ms |
204 KB |
Output is correct |
91 |
Correct |
0 ms |
204 KB |
Output is correct |
92 |
Correct |
3 ms |
844 KB |
Output is correct |
93 |
Correct |
69 ms |
14060 KB |
Output is correct |
94 |
Correct |
1 ms |
204 KB |
Output is correct |
95 |
Correct |
0 ms |
204 KB |
Output is correct |
96 |
Correct |
0 ms |
204 KB |
Output is correct |
97 |
Correct |
17 ms |
3688 KB |
Output is correct |
98 |
Correct |
65 ms |
14148 KB |
Output is correct |
99 |
Correct |
76 ms |
14312 KB |
Output is correct |
100 |
Correct |
64 ms |
14148 KB |
Output is correct |
101 |
Correct |
64 ms |
14068 KB |
Output is correct |
102 |
Correct |
63 ms |
14076 KB |
Output is correct |
103 |
Correct |
63 ms |
14060 KB |
Output is correct |
104 |
Correct |
64 ms |
14072 KB |
Output is correct |
105 |
Correct |
79 ms |
14072 KB |
Output is correct |