#include <bits/stdc++.h>
#include "supertrees.h"
using namespace std;
using ll = long long;
const int maxn=1e3+5;
int p[maxn];
int nw[maxn];
vector<int>v[maxn];
int ata(int nd){
if(p[nd] == nd) return nd;
return p[nd] = ata(p[nd]);
}
int par(int nd){
if(nw[nd] == nd) return nd;
return nw[nd] = ata(nw[nd]);
}
int construct(vector<vector<int>> a) {
int n = a.size();
for(int i = 0;i < n;i++) p[i] = nw[i] = i;
for(int i = 0;i < n;i++){
for(int j = 0;j < n;j++){
if(a[i][j] == 3) return 0;
if(a[i][j] == 1){
int x = ata(i),y = ata(j);
if(x != y) p[y] = x;
}
}
}
for(int i = 0;i < n;i++) ata(i);
vector<vector<int>>ed;
ed.resize(n);
for(int i = 0;i < n;i++) ed[i].resize(n);
for(int i = 0;i < n;i++){
if(p[i] != i){
if(a[i] != a[p[i]]) return 0;
ed[p[i]][i] = 1;
ed[i][p[i]] = 1;
}
else {
for(int j = 0;j < n;j++){
if(p[j] != j or i == j) continue;
if(a[i][j] == 2){
int x = par(i),y = par(j);
if(x != y) nw[j] = i;
}
}
}
}
for(int i = 0;i < n;i++){
if(p[i] != i) continue;
par(i);
v[nw[i]].push_back(i);
}
for(int i = 0;i < n;i++){
if(p[i] != i) continue;
if(nw[i] != i) continue;
if((int)v[i].size() == 2) return 0;
for(int j = 0;j < (int)v[i].size();j++){
for(int k = 0;k < j;k++){
if(a[v[i][j]][v[i][k]] != 2) return 0;
}
if(j > 0){
ed[v[i][j]][v[i][j-1]]=1;
ed[v[i][j-1]][v[i][j]]=1;
}
}
if((int)v[i].size() > 1) ed[v[i].back()][v[i][0]]=1;
if((int)v[i].size() > 1) ed[v[i][0]][v[i].back()]=1;
}
for(int i = 0;i < n;i++){
for(int j = 0;j < n;j++){
if(i == j) continue;
if(p[i] == p[j] and a[i][j] != 1) return 0;
if(nw[i] == nw[j] and a[i][j] != 2) return 0;
if(p[i] != p[j] and nw[p[i]] != nw[p[j]] and a[i][j] != 0) return 0;
}
}
build(ed);
return 1;
}
/*
4
1 1 2 2
1 1 2 2
2 2 1 2
2 2 2 1
2
1 0
0 1
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
11 ms |
1260 KB |
Output is correct |
7 |
Correct |
258 ms |
22508 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
11 ms |
1260 KB |
Output is correct |
7 |
Correct |
258 ms |
22508 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
11 ms |
1388 KB |
Output is correct |
13 |
Correct |
254 ms |
22380 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
6 ms |
876 KB |
Output is correct |
17 |
Correct |
121 ms |
12396 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
63 ms |
6124 KB |
Output is correct |
21 |
Correct |
256 ms |
22508 KB |
Output is correct |
22 |
Correct |
250 ms |
22380 KB |
Output is correct |
23 |
Correct |
295 ms |
22396 KB |
Output is correct |
24 |
Correct |
260 ms |
22656 KB |
Output is correct |
25 |
Correct |
108 ms |
12396 KB |
Output is correct |
26 |
Correct |
107 ms |
12396 KB |
Output is correct |
27 |
Correct |
266 ms |
22380 KB |
Output is correct |
28 |
Correct |
253 ms |
22508 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
13 ms |
1388 KB |
Output is correct |
9 |
Correct |
251 ms |
22508 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
12 ms |
1260 KB |
Output is correct |
13 |
Correct |
257 ms |
22380 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
6 ms |
876 KB |
Output is correct |
17 |
Correct |
125 ms |
12396 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
64 ms |
6164 KB |
Output is correct |
22 |
Correct |
257 ms |
22380 KB |
Output is correct |
23 |
Correct |
252 ms |
22380 KB |
Output is correct |
24 |
Correct |
268 ms |
22508 KB |
Output is correct |
25 |
Correct |
105 ms |
12524 KB |
Output is correct |
26 |
Correct |
109 ms |
12524 KB |
Output is correct |
27 |
Correct |
252 ms |
24044 KB |
Output is correct |
28 |
Correct |
270 ms |
24172 KB |
Output is correct |
29 |
Correct |
113 ms |
14188 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
91 ms |
6124 KB |
Output is correct |
5 |
Correct |
256 ms |
22508 KB |
Output is correct |
6 |
Correct |
257 ms |
22636 KB |
Output is correct |
7 |
Correct |
272 ms |
22380 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
91 ms |
6124 KB |
Output is correct |
10 |
Correct |
252 ms |
22380 KB |
Output is correct |
11 |
Correct |
249 ms |
22476 KB |
Output is correct |
12 |
Correct |
289 ms |
22476 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
65 ms |
6252 KB |
Output is correct |
17 |
Correct |
256 ms |
22420 KB |
Output is correct |
18 |
Correct |
263 ms |
22380 KB |
Output is correct |
19 |
Correct |
283 ms |
22396 KB |
Output is correct |
20 |
Correct |
262 ms |
22636 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
11 ms |
1260 KB |
Output is correct |
7 |
Correct |
258 ms |
22508 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
11 ms |
1388 KB |
Output is correct |
13 |
Correct |
254 ms |
22380 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
6 ms |
876 KB |
Output is correct |
17 |
Correct |
121 ms |
12396 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
63 ms |
6124 KB |
Output is correct |
21 |
Correct |
256 ms |
22508 KB |
Output is correct |
22 |
Correct |
250 ms |
22380 KB |
Output is correct |
23 |
Correct |
295 ms |
22396 KB |
Output is correct |
24 |
Correct |
260 ms |
22656 KB |
Output is correct |
25 |
Correct |
108 ms |
12396 KB |
Output is correct |
26 |
Correct |
107 ms |
12396 KB |
Output is correct |
27 |
Correct |
266 ms |
22380 KB |
Output is correct |
28 |
Correct |
253 ms |
22508 KB |
Output is correct |
29 |
Correct |
1 ms |
364 KB |
Output is correct |
30 |
Correct |
1 ms |
364 KB |
Output is correct |
31 |
Correct |
1 ms |
364 KB |
Output is correct |
32 |
Correct |
1 ms |
364 KB |
Output is correct |
33 |
Correct |
1 ms |
364 KB |
Output is correct |
34 |
Correct |
1 ms |
364 KB |
Output is correct |
35 |
Correct |
1 ms |
364 KB |
Output is correct |
36 |
Correct |
13 ms |
1388 KB |
Output is correct |
37 |
Correct |
251 ms |
22508 KB |
Output is correct |
38 |
Correct |
1 ms |
364 KB |
Output is correct |
39 |
Correct |
1 ms |
364 KB |
Output is correct |
40 |
Correct |
12 ms |
1260 KB |
Output is correct |
41 |
Correct |
257 ms |
22380 KB |
Output is correct |
42 |
Correct |
1 ms |
364 KB |
Output is correct |
43 |
Correct |
1 ms |
364 KB |
Output is correct |
44 |
Correct |
6 ms |
876 KB |
Output is correct |
45 |
Correct |
125 ms |
12396 KB |
Output is correct |
46 |
Correct |
1 ms |
364 KB |
Output is correct |
47 |
Correct |
1 ms |
364 KB |
Output is correct |
48 |
Correct |
1 ms |
364 KB |
Output is correct |
49 |
Correct |
64 ms |
6164 KB |
Output is correct |
50 |
Correct |
257 ms |
22380 KB |
Output is correct |
51 |
Correct |
252 ms |
22380 KB |
Output is correct |
52 |
Correct |
268 ms |
22508 KB |
Output is correct |
53 |
Correct |
105 ms |
12524 KB |
Output is correct |
54 |
Correct |
109 ms |
12524 KB |
Output is correct |
55 |
Correct |
252 ms |
24044 KB |
Output is correct |
56 |
Correct |
270 ms |
24172 KB |
Output is correct |
57 |
Correct |
113 ms |
14188 KB |
Output is correct |
58 |
Correct |
1 ms |
364 KB |
Output is correct |
59 |
Correct |
1 ms |
364 KB |
Output is correct |
60 |
Correct |
6 ms |
876 KB |
Output is correct |
61 |
Correct |
119 ms |
14188 KB |
Output is correct |
62 |
Correct |
1 ms |
364 KB |
Output is correct |
63 |
Correct |
1 ms |
492 KB |
Output is correct |
64 |
Correct |
1 ms |
364 KB |
Output is correct |
65 |
Correct |
64 ms |
6380 KB |
Output is correct |
66 |
Correct |
114 ms |
14188 KB |
Output is correct |
67 |
Correct |
111 ms |
14188 KB |
Output is correct |
68 |
Correct |
112 ms |
14188 KB |
Output is correct |
69 |
Correct |
118 ms |
14188 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
11 ms |
1260 KB |
Output is correct |
7 |
Correct |
258 ms |
22508 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
11 ms |
1388 KB |
Output is correct |
13 |
Correct |
254 ms |
22380 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
6 ms |
876 KB |
Output is correct |
17 |
Correct |
121 ms |
12396 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
63 ms |
6124 KB |
Output is correct |
21 |
Correct |
256 ms |
22508 KB |
Output is correct |
22 |
Correct |
250 ms |
22380 KB |
Output is correct |
23 |
Correct |
295 ms |
22396 KB |
Output is correct |
24 |
Correct |
260 ms |
22656 KB |
Output is correct |
25 |
Correct |
108 ms |
12396 KB |
Output is correct |
26 |
Correct |
107 ms |
12396 KB |
Output is correct |
27 |
Correct |
266 ms |
22380 KB |
Output is correct |
28 |
Correct |
253 ms |
22508 KB |
Output is correct |
29 |
Correct |
1 ms |
364 KB |
Output is correct |
30 |
Correct |
1 ms |
364 KB |
Output is correct |
31 |
Correct |
1 ms |
364 KB |
Output is correct |
32 |
Correct |
1 ms |
364 KB |
Output is correct |
33 |
Correct |
1 ms |
364 KB |
Output is correct |
34 |
Correct |
1 ms |
364 KB |
Output is correct |
35 |
Correct |
1 ms |
364 KB |
Output is correct |
36 |
Correct |
13 ms |
1388 KB |
Output is correct |
37 |
Correct |
251 ms |
22508 KB |
Output is correct |
38 |
Correct |
1 ms |
364 KB |
Output is correct |
39 |
Correct |
1 ms |
364 KB |
Output is correct |
40 |
Correct |
12 ms |
1260 KB |
Output is correct |
41 |
Correct |
257 ms |
22380 KB |
Output is correct |
42 |
Correct |
1 ms |
364 KB |
Output is correct |
43 |
Correct |
1 ms |
364 KB |
Output is correct |
44 |
Correct |
6 ms |
876 KB |
Output is correct |
45 |
Correct |
125 ms |
12396 KB |
Output is correct |
46 |
Correct |
1 ms |
364 KB |
Output is correct |
47 |
Correct |
1 ms |
364 KB |
Output is correct |
48 |
Correct |
1 ms |
364 KB |
Output is correct |
49 |
Correct |
64 ms |
6164 KB |
Output is correct |
50 |
Correct |
257 ms |
22380 KB |
Output is correct |
51 |
Correct |
252 ms |
22380 KB |
Output is correct |
52 |
Correct |
268 ms |
22508 KB |
Output is correct |
53 |
Correct |
105 ms |
12524 KB |
Output is correct |
54 |
Correct |
109 ms |
12524 KB |
Output is correct |
55 |
Correct |
252 ms |
24044 KB |
Output is correct |
56 |
Correct |
270 ms |
24172 KB |
Output is correct |
57 |
Correct |
113 ms |
14188 KB |
Output is correct |
58 |
Correct |
1 ms |
364 KB |
Output is correct |
59 |
Correct |
1 ms |
364 KB |
Output is correct |
60 |
Correct |
1 ms |
364 KB |
Output is correct |
61 |
Correct |
91 ms |
6124 KB |
Output is correct |
62 |
Correct |
256 ms |
22508 KB |
Output is correct |
63 |
Correct |
257 ms |
22636 KB |
Output is correct |
64 |
Correct |
272 ms |
22380 KB |
Output is correct |
65 |
Correct |
1 ms |
364 KB |
Output is correct |
66 |
Correct |
91 ms |
6124 KB |
Output is correct |
67 |
Correct |
252 ms |
22380 KB |
Output is correct |
68 |
Correct |
249 ms |
22476 KB |
Output is correct |
69 |
Correct |
289 ms |
22476 KB |
Output is correct |
70 |
Correct |
1 ms |
364 KB |
Output is correct |
71 |
Correct |
1 ms |
364 KB |
Output is correct |
72 |
Correct |
1 ms |
364 KB |
Output is correct |
73 |
Correct |
65 ms |
6252 KB |
Output is correct |
74 |
Correct |
256 ms |
22420 KB |
Output is correct |
75 |
Correct |
263 ms |
22380 KB |
Output is correct |
76 |
Correct |
283 ms |
22396 KB |
Output is correct |
77 |
Correct |
262 ms |
22636 KB |
Output is correct |
78 |
Correct |
1 ms |
364 KB |
Output is correct |
79 |
Correct |
1 ms |
364 KB |
Output is correct |
80 |
Correct |
6 ms |
876 KB |
Output is correct |
81 |
Correct |
119 ms |
14188 KB |
Output is correct |
82 |
Correct |
1 ms |
364 KB |
Output is correct |
83 |
Correct |
1 ms |
492 KB |
Output is correct |
84 |
Correct |
1 ms |
364 KB |
Output is correct |
85 |
Correct |
64 ms |
6380 KB |
Output is correct |
86 |
Correct |
114 ms |
14188 KB |
Output is correct |
87 |
Correct |
111 ms |
14188 KB |
Output is correct |
88 |
Correct |
112 ms |
14188 KB |
Output is correct |
89 |
Correct |
118 ms |
14188 KB |
Output is correct |
90 |
Correct |
1 ms |
364 KB |
Output is correct |
91 |
Correct |
1 ms |
364 KB |
Output is correct |
92 |
Correct |
5 ms |
748 KB |
Output is correct |
93 |
Correct |
115 ms |
10220 KB |
Output is correct |
94 |
Correct |
1 ms |
364 KB |
Output is correct |
95 |
Correct |
1 ms |
364 KB |
Output is correct |
96 |
Correct |
1 ms |
364 KB |
Output is correct |
97 |
Correct |
26 ms |
2796 KB |
Output is correct |
98 |
Correct |
119 ms |
10220 KB |
Output is correct |
99 |
Correct |
104 ms |
10220 KB |
Output is correct |
100 |
Correct |
106 ms |
10220 KB |
Output is correct |
101 |
Correct |
113 ms |
10220 KB |
Output is correct |
102 |
Correct |
104 ms |
10220 KB |
Output is correct |
103 |
Correct |
109 ms |
10220 KB |
Output is correct |
104 |
Correct |
113 ms |
10220 KB |
Output is correct |
105 |
Correct |
112 ms |
10220 KB |
Output is correct |