#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e3 + 20;
int cnt[maxn][maxn];
vector<vector<int>> res;
bool flag[maxn];
int n;
void add_edge(int u, int v) {
res[u][v] = true;
res[v][u] = true;
}
bool solve(vector<int> comp) {
for (auto u: comp) {
for (auto v: comp) {
if (cnt[u][v] == 0) {
return false;
}
}
}
for (auto i: comp) {
flag[i] = false;
}
vector<vector<int>> chains;
for (auto i: comp) {
if (!flag[i]) {
flag[i] = true;
vector<int> chain = {i};
int pt = 0;
int sz = 1;
while (pt < sz) {
int u = chain[pt++];
for (int v = 0; v < n; v++) {
if (!flag[v] && cnt[u][v] == 1) {
flag[v] = true;
chain.push_back(v);
sz++;
}
}
}
for (auto u: chain) {
for (auto v: chain) {
if (cnt[u][v] != 1) {
return false;
}
}
}
for (int i = 0; i < (int)chain.size() - 1; i++) {
add_edge(chain[i], chain[i + 1]);
}
chains.push_back(chain);
}
}
int sz = chains.size();
if (sz == 2) {
return false;
}
if (sz >= 3) {
for (int i = 0; i < sz; i++) {
add_edge(chains[i].back(), chains[(i + 1) % sz].back());
}
}
return true;
}
int construct(vector<vector<int>> _cnt) {
n = _cnt.size();
res.resize(n, vector<int>(n, 0));
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
cnt[i][j] = _cnt[i][j];
if (cnt[i][j] == 3) {
return 0;
}
}
}
for (int i = 0; i < n; i++) {
if (!flag[i]) {
flag[i] = true;
vector<int> comp = {i};
int pt = 0;
int sz = 1;
while (pt < sz) {
int u = comp[pt++];
for (int v = 0; v < n; v++) {
if (!flag[v] && cnt[u][v] > 0) {
flag[v] = true;
comp.push_back(v);
sz++;
}
}
}
if (!solve(comp)) {
return 0;
}
}
}
build(res);
return 1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
7 ms |
2004 KB |
Output is correct |
7 |
Correct |
154 ms |
26004 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
7 ms |
2004 KB |
Output is correct |
7 |
Correct |
154 ms |
26004 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 |
340 KB |
Output is correct |
12 |
Correct |
7 ms |
1960 KB |
Output is correct |
13 |
Correct |
158 ms |
25932 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
3 ms |
1492 KB |
Output is correct |
17 |
Correct |
77 ms |
16020 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
41 ms |
7684 KB |
Output is correct |
21 |
Correct |
160 ms |
25936 KB |
Output is correct |
22 |
Correct |
155 ms |
25932 KB |
Output is correct |
23 |
Correct |
187 ms |
26080 KB |
Output is correct |
24 |
Correct |
151 ms |
25932 KB |
Output is correct |
25 |
Correct |
63 ms |
16008 KB |
Output is correct |
26 |
Correct |
60 ms |
16120 KB |
Output is correct |
27 |
Correct |
161 ms |
25996 KB |
Output is correct |
28 |
Correct |
150 ms |
25992 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 |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
7 ms |
1876 KB |
Output is correct |
9 |
Correct |
151 ms |
26008 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
304 KB |
Output is correct |
12 |
Correct |
7 ms |
2004 KB |
Output is correct |
13 |
Correct |
181 ms |
26008 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
3 ms |
1492 KB |
Output is correct |
17 |
Correct |
64 ms |
16140 KB |
Output is correct |
18 |
Correct |
0 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 |
38 ms |
7696 KB |
Output is correct |
22 |
Correct |
152 ms |
26024 KB |
Output is correct |
23 |
Correct |
152 ms |
26012 KB |
Output is correct |
24 |
Correct |
156 ms |
26120 KB |
Output is correct |
25 |
Correct |
62 ms |
16076 KB |
Output is correct |
26 |
Correct |
61 ms |
16076 KB |
Output is correct |
27 |
Correct |
181 ms |
25924 KB |
Output is correct |
28 |
Correct |
158 ms |
26132 KB |
Output is correct |
29 |
Correct |
63 ms |
16024 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 |
39 ms |
7728 KB |
Output is correct |
5 |
Correct |
152 ms |
26004 KB |
Output is correct |
6 |
Correct |
150 ms |
25972 KB |
Output is correct |
7 |
Correct |
155 ms |
26012 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
42 ms |
7764 KB |
Output is correct |
10 |
Correct |
154 ms |
25996 KB |
Output is correct |
11 |
Correct |
151 ms |
26024 KB |
Output is correct |
12 |
Correct |
155 ms |
25928 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
40 ms |
8188 KB |
Output is correct |
17 |
Correct |
153 ms |
27960 KB |
Output is correct |
18 |
Correct |
152 ms |
27996 KB |
Output is correct |
19 |
Correct |
150 ms |
27960 KB |
Output is correct |
20 |
Correct |
185 ms |
27916 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
7 ms |
2004 KB |
Output is correct |
7 |
Correct |
154 ms |
26004 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 |
340 KB |
Output is correct |
12 |
Correct |
7 ms |
1960 KB |
Output is correct |
13 |
Correct |
158 ms |
25932 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
3 ms |
1492 KB |
Output is correct |
17 |
Correct |
77 ms |
16020 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
41 ms |
7684 KB |
Output is correct |
21 |
Correct |
160 ms |
25936 KB |
Output is correct |
22 |
Correct |
155 ms |
25932 KB |
Output is correct |
23 |
Correct |
187 ms |
26080 KB |
Output is correct |
24 |
Correct |
151 ms |
25932 KB |
Output is correct |
25 |
Correct |
63 ms |
16008 KB |
Output is correct |
26 |
Correct |
60 ms |
16120 KB |
Output is correct |
27 |
Correct |
161 ms |
25996 KB |
Output is correct |
28 |
Correct |
150 ms |
25992 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 |
0 ms |
212 KB |
Output is correct |
34 |
Correct |
0 ms |
212 KB |
Output is correct |
35 |
Correct |
0 ms |
340 KB |
Output is correct |
36 |
Correct |
7 ms |
1876 KB |
Output is correct |
37 |
Correct |
151 ms |
26008 KB |
Output is correct |
38 |
Correct |
0 ms |
212 KB |
Output is correct |
39 |
Correct |
1 ms |
304 KB |
Output is correct |
40 |
Correct |
7 ms |
2004 KB |
Output is correct |
41 |
Correct |
181 ms |
26008 KB |
Output is correct |
42 |
Correct |
0 ms |
212 KB |
Output is correct |
43 |
Correct |
1 ms |
340 KB |
Output is correct |
44 |
Correct |
3 ms |
1492 KB |
Output is correct |
45 |
Correct |
64 ms |
16140 KB |
Output is correct |
46 |
Correct |
0 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 |
38 ms |
7696 KB |
Output is correct |
50 |
Correct |
152 ms |
26024 KB |
Output is correct |
51 |
Correct |
152 ms |
26012 KB |
Output is correct |
52 |
Correct |
156 ms |
26120 KB |
Output is correct |
53 |
Correct |
62 ms |
16076 KB |
Output is correct |
54 |
Correct |
61 ms |
16076 KB |
Output is correct |
55 |
Correct |
181 ms |
25924 KB |
Output is correct |
56 |
Correct |
158 ms |
26132 KB |
Output is correct |
57 |
Correct |
63 ms |
16024 KB |
Output is correct |
58 |
Correct |
0 ms |
212 KB |
Output is correct |
59 |
Correct |
0 ms |
340 KB |
Output is correct |
60 |
Correct |
3 ms |
1492 KB |
Output is correct |
61 |
Correct |
63 ms |
16140 KB |
Output is correct |
62 |
Correct |
0 ms |
212 KB |
Output is correct |
63 |
Correct |
0 ms |
340 KB |
Output is correct |
64 |
Correct |
0 ms |
340 KB |
Output is correct |
65 |
Correct |
39 ms |
7748 KB |
Output is correct |
66 |
Correct |
76 ms |
18044 KB |
Output is correct |
67 |
Correct |
62 ms |
18048 KB |
Output is correct |
68 |
Correct |
62 ms |
18048 KB |
Output is correct |
69 |
Correct |
64 ms |
18048 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
7 ms |
2004 KB |
Output is correct |
7 |
Correct |
154 ms |
26004 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 |
340 KB |
Output is correct |
12 |
Correct |
7 ms |
1960 KB |
Output is correct |
13 |
Correct |
158 ms |
25932 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
3 ms |
1492 KB |
Output is correct |
17 |
Correct |
77 ms |
16020 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
41 ms |
7684 KB |
Output is correct |
21 |
Correct |
160 ms |
25936 KB |
Output is correct |
22 |
Correct |
155 ms |
25932 KB |
Output is correct |
23 |
Correct |
187 ms |
26080 KB |
Output is correct |
24 |
Correct |
151 ms |
25932 KB |
Output is correct |
25 |
Correct |
63 ms |
16008 KB |
Output is correct |
26 |
Correct |
60 ms |
16120 KB |
Output is correct |
27 |
Correct |
161 ms |
25996 KB |
Output is correct |
28 |
Correct |
150 ms |
25992 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 |
0 ms |
212 KB |
Output is correct |
34 |
Correct |
0 ms |
212 KB |
Output is correct |
35 |
Correct |
0 ms |
340 KB |
Output is correct |
36 |
Correct |
7 ms |
1876 KB |
Output is correct |
37 |
Correct |
151 ms |
26008 KB |
Output is correct |
38 |
Correct |
0 ms |
212 KB |
Output is correct |
39 |
Correct |
1 ms |
304 KB |
Output is correct |
40 |
Correct |
7 ms |
2004 KB |
Output is correct |
41 |
Correct |
181 ms |
26008 KB |
Output is correct |
42 |
Correct |
0 ms |
212 KB |
Output is correct |
43 |
Correct |
1 ms |
340 KB |
Output is correct |
44 |
Correct |
3 ms |
1492 KB |
Output is correct |
45 |
Correct |
64 ms |
16140 KB |
Output is correct |
46 |
Correct |
0 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 |
38 ms |
7696 KB |
Output is correct |
50 |
Correct |
152 ms |
26024 KB |
Output is correct |
51 |
Correct |
152 ms |
26012 KB |
Output is correct |
52 |
Correct |
156 ms |
26120 KB |
Output is correct |
53 |
Correct |
62 ms |
16076 KB |
Output is correct |
54 |
Correct |
61 ms |
16076 KB |
Output is correct |
55 |
Correct |
181 ms |
25924 KB |
Output is correct |
56 |
Correct |
158 ms |
26132 KB |
Output is correct |
57 |
Correct |
63 ms |
16024 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 |
39 ms |
7728 KB |
Output is correct |
62 |
Correct |
152 ms |
26004 KB |
Output is correct |
63 |
Correct |
150 ms |
25972 KB |
Output is correct |
64 |
Correct |
155 ms |
26012 KB |
Output is correct |
65 |
Correct |
0 ms |
212 KB |
Output is correct |
66 |
Correct |
42 ms |
7764 KB |
Output is correct |
67 |
Correct |
154 ms |
25996 KB |
Output is correct |
68 |
Correct |
151 ms |
26024 KB |
Output is correct |
69 |
Correct |
155 ms |
25928 KB |
Output is correct |
70 |
Correct |
0 ms |
212 KB |
Output is correct |
71 |
Correct |
0 ms |
340 KB |
Output is correct |
72 |
Correct |
0 ms |
212 KB |
Output is correct |
73 |
Correct |
40 ms |
8188 KB |
Output is correct |
74 |
Correct |
153 ms |
27960 KB |
Output is correct |
75 |
Correct |
152 ms |
27996 KB |
Output is correct |
76 |
Correct |
150 ms |
27960 KB |
Output is correct |
77 |
Correct |
185 ms |
27916 KB |
Output is correct |
78 |
Correct |
0 ms |
212 KB |
Output is correct |
79 |
Correct |
0 ms |
340 KB |
Output is correct |
80 |
Correct |
3 ms |
1492 KB |
Output is correct |
81 |
Correct |
63 ms |
16140 KB |
Output is correct |
82 |
Correct |
0 ms |
212 KB |
Output is correct |
83 |
Correct |
0 ms |
340 KB |
Output is correct |
84 |
Correct |
0 ms |
340 KB |
Output is correct |
85 |
Correct |
39 ms |
7748 KB |
Output is correct |
86 |
Correct |
76 ms |
18044 KB |
Output is correct |
87 |
Correct |
62 ms |
18048 KB |
Output is correct |
88 |
Correct |
62 ms |
18048 KB |
Output is correct |
89 |
Correct |
64 ms |
18048 KB |
Output is correct |
90 |
Correct |
1 ms |
212 KB |
Output is correct |
91 |
Correct |
0 ms |
212 KB |
Output is correct |
92 |
Correct |
3 ms |
852 KB |
Output is correct |
93 |
Correct |
69 ms |
14080 KB |
Output is correct |
94 |
Correct |
0 ms |
212 KB |
Output is correct |
95 |
Correct |
0 ms |
212 KB |
Output is correct |
96 |
Correct |
0 ms |
304 KB |
Output is correct |
97 |
Correct |
15 ms |
3852 KB |
Output is correct |
98 |
Correct |
60 ms |
14284 KB |
Output is correct |
99 |
Correct |
60 ms |
14600 KB |
Output is correct |
100 |
Correct |
60 ms |
14352 KB |
Output is correct |
101 |
Correct |
58 ms |
15408 KB |
Output is correct |
102 |
Correct |
70 ms |
14204 KB |
Output is correct |
103 |
Correct |
62 ms |
14088 KB |
Output is correct |
104 |
Correct |
59 ms |
14092 KB |
Output is correct |
105 |
Correct |
63 ms |
14096 KB |
Output is correct |