#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;
int comp[1010], tree[1010], comps, sz[1010], roots[1010][1010];
int construct(std::vector<std::vector<int>> p) {
for(auto i:p)
for(auto j: i)
if(j>2)
return 0;
int n = p.size();
std::vector<std::vector<int>> answer(n,vector<int>(n,0));
for(int i = 0; i < n; i++) {
bool determined=0;
bitset<1024>notree;
bitset<1024>notcomp;
for(int j = 0; j < i; j++) {
if(determined) {
if(!p[i][j]){
if(comp[i]==comp[j])
return 0;
} else if(comp[i]!=comp[j])
return 0;
else if(p[i][j]==1&&tree[i]!=tree[j])
return 0;
} else {
if(!p[i][j])
notcomp[comp[j]]=1;
else if(p[i][j]-1) {
if(notcomp[comp[j]]) return 0;
notcomp.reset();
notcomp.flip();
notcomp[comp[j]] = 0;
notree[tree[j]] = 1;
comp[i] = comp[j];
} else {
if(notcomp[comp[j]]) return 0;
if(notree[tree[j]]) return 0;
answer[i][j] = answer[j][i] = 1;
tree[i] = tree[j];
comp[i] = comp[j];
notcomp.reset();
notcomp.flip();
notcomp[comp[j]] = 0;
notree.reset();
notree.flip();
notree[tree[j]] = 0;
determined = 1;
}
}
}
if(!comp[i]) {
comp[i] = ++comps;
roots[comp[i]][1] = i;
sz[comps] = tree[i] = 1;
} else if(!tree[i]) {
tree[i] = ++sz[comp[i]];
roots[comp[i]][sz[comp[i]]] = i;
}
if(notcomp[comp[i]]||notree[tree[i]]) return 0;
}
for(int i = 1; i <= comps; i++) {
if(sz[i]==1) continue;
if(sz[i]==2) return 0;
for(int j = 1; j < sz[i]; j++) {
answer[roots[i][j]][roots[i][j+1]] = answer[roots[i][j+1]][roots[i][j]] = 1;
}
answer[roots[i][1]][roots[i][sz[i]]] = answer[roots[i][sz[i]]][roots[i][1]] = 1;
}
build(answer);
return 1;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 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 |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
6 ms |
1176 KB |
Output is correct |
7 |
Correct |
149 ms |
22040 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 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 |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
6 ms |
1176 KB |
Output is correct |
7 |
Correct |
149 ms |
22040 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 |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
7 ms |
1876 KB |
Output is correct |
13 |
Correct |
155 ms |
26012 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
3 ms |
724 KB |
Output is correct |
17 |
Correct |
65 ms |
12044 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
39 ms |
5956 KB |
Output is correct |
21 |
Correct |
152 ms |
22040 KB |
Output is correct |
22 |
Correct |
159 ms |
23564 KB |
Output is correct |
23 |
Correct |
160 ms |
22024 KB |
Output is correct |
24 |
Correct |
154 ms |
25736 KB |
Output is correct |
25 |
Correct |
63 ms |
12172 KB |
Output is correct |
26 |
Correct |
63 ms |
13192 KB |
Output is correct |
27 |
Correct |
158 ms |
22040 KB |
Output is correct |
28 |
Correct |
156 ms |
25748 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
7 ms |
1984 KB |
Output is correct |
9 |
Correct |
157 ms |
26952 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
7 ms |
1236 KB |
Output is correct |
13 |
Correct |
162 ms |
22984 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
3 ms |
852 KB |
Output is correct |
17 |
Correct |
66 ms |
13840 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 |
40 ms |
6468 KB |
Output is correct |
22 |
Correct |
158 ms |
22988 KB |
Output is correct |
23 |
Correct |
153 ms |
23756 KB |
Output is correct |
24 |
Correct |
198 ms |
23012 KB |
Output is correct |
25 |
Correct |
65 ms |
17580 KB |
Output is correct |
26 |
Correct |
64 ms |
13772 KB |
Output is correct |
27 |
Correct |
157 ms |
23892 KB |
Output is correct |
28 |
Correct |
162 ms |
23032 KB |
Output is correct |
29 |
Correct |
66 ms |
17544 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
38 ms |
5964 KB |
Output is correct |
5 |
Correct |
152 ms |
22020 KB |
Output is correct |
6 |
Correct |
156 ms |
23576 KB |
Output is correct |
7 |
Correct |
156 ms |
22040 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
38 ms |
6032 KB |
Output is correct |
10 |
Correct |
154 ms |
22000 KB |
Output is correct |
11 |
Correct |
152 ms |
22812 KB |
Output is correct |
12 |
Correct |
160 ms |
22028 KB |
Output is correct |
13 |
Correct |
1 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 |
39 ms |
6148 KB |
Output is correct |
17 |
Correct |
154 ms |
22056 KB |
Output is correct |
18 |
Correct |
153 ms |
22024 KB |
Output is correct |
19 |
Correct |
166 ms |
22172 KB |
Output is correct |
20 |
Correct |
155 ms |
25716 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 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 |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
6 ms |
1176 KB |
Output is correct |
7 |
Correct |
149 ms |
22040 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 |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
7 ms |
1876 KB |
Output is correct |
13 |
Correct |
155 ms |
26012 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
3 ms |
724 KB |
Output is correct |
17 |
Correct |
65 ms |
12044 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
39 ms |
5956 KB |
Output is correct |
21 |
Correct |
152 ms |
22040 KB |
Output is correct |
22 |
Correct |
159 ms |
23564 KB |
Output is correct |
23 |
Correct |
160 ms |
22024 KB |
Output is correct |
24 |
Correct |
154 ms |
25736 KB |
Output is correct |
25 |
Correct |
63 ms |
12172 KB |
Output is correct |
26 |
Correct |
63 ms |
13192 KB |
Output is correct |
27 |
Correct |
158 ms |
22040 KB |
Output is correct |
28 |
Correct |
156 ms |
25748 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 |
Correct |
0 ms |
212 KB |
Output is correct |
33 |
Correct |
1 ms |
212 KB |
Output is correct |
34 |
Correct |
1 ms |
340 KB |
Output is correct |
35 |
Correct |
1 ms |
340 KB |
Output is correct |
36 |
Correct |
7 ms |
1984 KB |
Output is correct |
37 |
Correct |
157 ms |
26952 KB |
Output is correct |
38 |
Correct |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
0 ms |
212 KB |
Output is correct |
40 |
Correct |
7 ms |
1236 KB |
Output is correct |
41 |
Correct |
162 ms |
22984 KB |
Output is correct |
42 |
Correct |
1 ms |
212 KB |
Output is correct |
43 |
Correct |
1 ms |
340 KB |
Output is correct |
44 |
Correct |
3 ms |
852 KB |
Output is correct |
45 |
Correct |
66 ms |
13840 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 |
40 ms |
6468 KB |
Output is correct |
50 |
Correct |
158 ms |
22988 KB |
Output is correct |
51 |
Correct |
153 ms |
23756 KB |
Output is correct |
52 |
Correct |
198 ms |
23012 KB |
Output is correct |
53 |
Correct |
65 ms |
17580 KB |
Output is correct |
54 |
Correct |
64 ms |
13772 KB |
Output is correct |
55 |
Correct |
157 ms |
23892 KB |
Output is correct |
56 |
Correct |
162 ms |
23032 KB |
Output is correct |
57 |
Correct |
66 ms |
17544 KB |
Output is correct |
58 |
Correct |
1 ms |
212 KB |
Output is correct |
59 |
Correct |
1 ms |
256 KB |
Output is correct |
60 |
Correct |
3 ms |
804 KB |
Output is correct |
61 |
Correct |
66 ms |
13772 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 |
340 KB |
Output is correct |
65 |
Correct |
41 ms |
6520 KB |
Output is correct |
66 |
Correct |
66 ms |
14028 KB |
Output is correct |
67 |
Correct |
65 ms |
14132 KB |
Output is correct |
68 |
Correct |
68 ms |
14200 KB |
Output is correct |
69 |
Correct |
66 ms |
17784 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 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 |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
6 ms |
1176 KB |
Output is correct |
7 |
Correct |
149 ms |
22040 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 |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
7 ms |
1876 KB |
Output is correct |
13 |
Correct |
155 ms |
26012 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
3 ms |
724 KB |
Output is correct |
17 |
Correct |
65 ms |
12044 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
39 ms |
5956 KB |
Output is correct |
21 |
Correct |
152 ms |
22040 KB |
Output is correct |
22 |
Correct |
159 ms |
23564 KB |
Output is correct |
23 |
Correct |
160 ms |
22024 KB |
Output is correct |
24 |
Correct |
154 ms |
25736 KB |
Output is correct |
25 |
Correct |
63 ms |
12172 KB |
Output is correct |
26 |
Correct |
63 ms |
13192 KB |
Output is correct |
27 |
Correct |
158 ms |
22040 KB |
Output is correct |
28 |
Correct |
156 ms |
25748 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 |
Correct |
0 ms |
212 KB |
Output is correct |
33 |
Correct |
1 ms |
212 KB |
Output is correct |
34 |
Correct |
1 ms |
340 KB |
Output is correct |
35 |
Correct |
1 ms |
340 KB |
Output is correct |
36 |
Correct |
7 ms |
1984 KB |
Output is correct |
37 |
Correct |
157 ms |
26952 KB |
Output is correct |
38 |
Correct |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
0 ms |
212 KB |
Output is correct |
40 |
Correct |
7 ms |
1236 KB |
Output is correct |
41 |
Correct |
162 ms |
22984 KB |
Output is correct |
42 |
Correct |
1 ms |
212 KB |
Output is correct |
43 |
Correct |
1 ms |
340 KB |
Output is correct |
44 |
Correct |
3 ms |
852 KB |
Output is correct |
45 |
Correct |
66 ms |
13840 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 |
40 ms |
6468 KB |
Output is correct |
50 |
Correct |
158 ms |
22988 KB |
Output is correct |
51 |
Correct |
153 ms |
23756 KB |
Output is correct |
52 |
Correct |
198 ms |
23012 KB |
Output is correct |
53 |
Correct |
65 ms |
17580 KB |
Output is correct |
54 |
Correct |
64 ms |
13772 KB |
Output is correct |
55 |
Correct |
157 ms |
23892 KB |
Output is correct |
56 |
Correct |
162 ms |
23032 KB |
Output is correct |
57 |
Correct |
66 ms |
17544 KB |
Output is correct |
58 |
Correct |
0 ms |
212 KB |
Output is correct |
59 |
Correct |
0 ms |
212 KB |
Output is correct |
60 |
Correct |
0 ms |
212 KB |
Output is correct |
61 |
Correct |
38 ms |
5964 KB |
Output is correct |
62 |
Correct |
152 ms |
22020 KB |
Output is correct |
63 |
Correct |
156 ms |
23576 KB |
Output is correct |
64 |
Correct |
156 ms |
22040 KB |
Output is correct |
65 |
Correct |
0 ms |
212 KB |
Output is correct |
66 |
Correct |
38 ms |
6032 KB |
Output is correct |
67 |
Correct |
154 ms |
22000 KB |
Output is correct |
68 |
Correct |
152 ms |
22812 KB |
Output is correct |
69 |
Correct |
160 ms |
22028 KB |
Output is correct |
70 |
Correct |
1 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 |
39 ms |
6148 KB |
Output is correct |
74 |
Correct |
154 ms |
22056 KB |
Output is correct |
75 |
Correct |
153 ms |
22024 KB |
Output is correct |
76 |
Correct |
166 ms |
22172 KB |
Output is correct |
77 |
Correct |
155 ms |
25716 KB |
Output is correct |
78 |
Correct |
1 ms |
212 KB |
Output is correct |
79 |
Correct |
1 ms |
256 KB |
Output is correct |
80 |
Correct |
3 ms |
804 KB |
Output is correct |
81 |
Correct |
66 ms |
13772 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 |
340 KB |
Output is correct |
85 |
Correct |
41 ms |
6520 KB |
Output is correct |
86 |
Correct |
66 ms |
14028 KB |
Output is correct |
87 |
Correct |
65 ms |
14132 KB |
Output is correct |
88 |
Correct |
68 ms |
14200 KB |
Output is correct |
89 |
Correct |
66 ms |
17784 KB |
Output is correct |
90 |
Correct |
1 ms |
212 KB |
Output is correct |
91 |
Correct |
1 ms |
212 KB |
Output is correct |
92 |
Correct |
3 ms |
596 KB |
Output is correct |
93 |
Correct |
62 ms |
10088 KB |
Output is correct |
94 |
Correct |
0 ms |
212 KB |
Output is correct |
95 |
Correct |
1 ms |
212 KB |
Output is correct |
96 |
Correct |
0 ms |
308 KB |
Output is correct |
97 |
Correct |
16 ms |
2688 KB |
Output is correct |
98 |
Correct |
62 ms |
10104 KB |
Output is correct |
99 |
Correct |
68 ms |
10084 KB |
Output is correct |
100 |
Correct |
61 ms |
10084 KB |
Output is correct |
101 |
Correct |
60 ms |
10092 KB |
Output is correct |
102 |
Correct |
58 ms |
10016 KB |
Output is correct |
103 |
Correct |
58 ms |
10060 KB |
Output is correct |
104 |
Correct |
57 ms |
10040 KB |
Output is correct |
105 |
Correct |
62 ms |
10088 KB |
Output is correct |