#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 (int i = 0; i < (int)comp.size() - 1; i++) {
add_edge(comp[i], comp[i + 1]);
}
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;
}
}
}
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 |
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 |
340 KB |
Output is correct |
6 |
Correct |
7 ms |
2004 KB |
Output is correct |
7 |
Correct |
159 ms |
25932 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 |
340 KB |
Output is correct |
6 |
Correct |
7 ms |
2004 KB |
Output is correct |
7 |
Correct |
159 ms |
25932 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 |
1876 KB |
Output is correct |
13 |
Correct |
155 ms |
26016 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 |
65 ms |
16148 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
39 ms |
7784 KB |
Output is correct |
21 |
Correct |
158 ms |
25932 KB |
Output is correct |
22 |
Correct |
169 ms |
25996 KB |
Output is correct |
23 |
Correct |
159 ms |
26012 KB |
Output is correct |
24 |
Correct |
159 ms |
26004 KB |
Output is correct |
25 |
Correct |
82 ms |
16008 KB |
Output is correct |
26 |
Correct |
63 ms |
16008 KB |
Output is correct |
27 |
Correct |
159 ms |
25932 KB |
Output is correct |
28 |
Correct |
159 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 |
1 ms |
308 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
7 ms |
1984 KB |
Output is correct |
9 |
Correct |
157 ms |
28028 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
308 KB |
Output is correct |
12 |
Correct |
7 ms |
2004 KB |
Output is correct |
13 |
Correct |
154 ms |
27904 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
308 KB |
Output is correct |
16 |
Correct |
3 ms |
1576 KB |
Output is correct |
17 |
Correct |
65 ms |
18048 KB |
Output is correct |
18 |
Correct |
1 ms |
304 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
45 ms |
8248 KB |
Output is correct |
22 |
Correct |
156 ms |
27980 KB |
Output is correct |
23 |
Correct |
158 ms |
27956 KB |
Output is correct |
24 |
Correct |
158 ms |
27996 KB |
Output is correct |
25 |
Correct |
76 ms |
18092 KB |
Output is correct |
26 |
Correct |
62 ms |
18056 KB |
Output is correct |
27 |
Correct |
167 ms |
27928 KB |
Output is correct |
28 |
Correct |
162 ms |
28000 KB |
Output is correct |
29 |
Correct |
76 ms |
18048 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 |
8176 KB |
Output is correct |
5 |
Correct |
156 ms |
26668 KB |
Output is correct |
6 |
Correct |
159 ms |
26828 KB |
Output is correct |
7 |
Correct |
159 ms |
26612 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
39 ms |
8140 KB |
Output is correct |
10 |
Correct |
156 ms |
26616 KB |
Output is correct |
11 |
Correct |
156 ms |
26620 KB |
Output is correct |
12 |
Correct |
165 ms |
26680 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Incorrect |
1 ms |
340 KB |
Too many ways to get from 0 to 4, should be 1 found no less than 2 |
16 |
Halted |
0 ms |
0 KB |
- |
# |
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 |
340 KB |
Output is correct |
6 |
Correct |
7 ms |
2004 KB |
Output is correct |
7 |
Correct |
159 ms |
25932 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 |
1876 KB |
Output is correct |
13 |
Correct |
155 ms |
26016 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 |
65 ms |
16148 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
39 ms |
7784 KB |
Output is correct |
21 |
Correct |
158 ms |
25932 KB |
Output is correct |
22 |
Correct |
169 ms |
25996 KB |
Output is correct |
23 |
Correct |
159 ms |
26012 KB |
Output is correct |
24 |
Correct |
159 ms |
26004 KB |
Output is correct |
25 |
Correct |
82 ms |
16008 KB |
Output is correct |
26 |
Correct |
63 ms |
16008 KB |
Output is correct |
27 |
Correct |
159 ms |
25932 KB |
Output is correct |
28 |
Correct |
159 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 |
1 ms |
308 KB |
Output is correct |
34 |
Correct |
1 ms |
212 KB |
Output is correct |
35 |
Correct |
0 ms |
340 KB |
Output is correct |
36 |
Correct |
7 ms |
1984 KB |
Output is correct |
37 |
Correct |
157 ms |
28028 KB |
Output is correct |
38 |
Correct |
0 ms |
212 KB |
Output is correct |
39 |
Correct |
0 ms |
308 KB |
Output is correct |
40 |
Correct |
7 ms |
2004 KB |
Output is correct |
41 |
Correct |
154 ms |
27904 KB |
Output is correct |
42 |
Correct |
1 ms |
212 KB |
Output is correct |
43 |
Correct |
0 ms |
308 KB |
Output is correct |
44 |
Correct |
3 ms |
1576 KB |
Output is correct |
45 |
Correct |
65 ms |
18048 KB |
Output is correct |
46 |
Correct |
1 ms |
304 KB |
Output is correct |
47 |
Correct |
0 ms |
212 KB |
Output is correct |
48 |
Correct |
1 ms |
212 KB |
Output is correct |
49 |
Correct |
45 ms |
8248 KB |
Output is correct |
50 |
Correct |
156 ms |
27980 KB |
Output is correct |
51 |
Correct |
158 ms |
27956 KB |
Output is correct |
52 |
Correct |
158 ms |
27996 KB |
Output is correct |
53 |
Correct |
76 ms |
18092 KB |
Output is correct |
54 |
Correct |
62 ms |
18056 KB |
Output is correct |
55 |
Correct |
167 ms |
27928 KB |
Output is correct |
56 |
Correct |
162 ms |
28000 KB |
Output is correct |
57 |
Correct |
76 ms |
18048 KB |
Output is correct |
58 |
Correct |
1 ms |
308 KB |
Output is correct |
59 |
Correct |
1 ms |
340 KB |
Output is correct |
60 |
Correct |
5 ms |
1620 KB |
Output is correct |
61 |
Correct |
64 ms |
18060 KB |
Output is correct |
62 |
Correct |
0 ms |
212 KB |
Output is correct |
63 |
Correct |
1 ms |
340 KB |
Output is correct |
64 |
Correct |
1 ms |
340 KB |
Output is correct |
65 |
Incorrect |
39 ms |
8212 KB |
Too many ways to get from 1 to 269, should be 1 found no less than 2 |
66 |
Halted |
0 ms |
0 KB |
- |
# |
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 |
340 KB |
Output is correct |
6 |
Correct |
7 ms |
2004 KB |
Output is correct |
7 |
Correct |
159 ms |
25932 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 |
1876 KB |
Output is correct |
13 |
Correct |
155 ms |
26016 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 |
65 ms |
16148 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
39 ms |
7784 KB |
Output is correct |
21 |
Correct |
158 ms |
25932 KB |
Output is correct |
22 |
Correct |
169 ms |
25996 KB |
Output is correct |
23 |
Correct |
159 ms |
26012 KB |
Output is correct |
24 |
Correct |
159 ms |
26004 KB |
Output is correct |
25 |
Correct |
82 ms |
16008 KB |
Output is correct |
26 |
Correct |
63 ms |
16008 KB |
Output is correct |
27 |
Correct |
159 ms |
25932 KB |
Output is correct |
28 |
Correct |
159 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 |
1 ms |
308 KB |
Output is correct |
34 |
Correct |
1 ms |
212 KB |
Output is correct |
35 |
Correct |
0 ms |
340 KB |
Output is correct |
36 |
Correct |
7 ms |
1984 KB |
Output is correct |
37 |
Correct |
157 ms |
28028 KB |
Output is correct |
38 |
Correct |
0 ms |
212 KB |
Output is correct |
39 |
Correct |
0 ms |
308 KB |
Output is correct |
40 |
Correct |
7 ms |
2004 KB |
Output is correct |
41 |
Correct |
154 ms |
27904 KB |
Output is correct |
42 |
Correct |
1 ms |
212 KB |
Output is correct |
43 |
Correct |
0 ms |
308 KB |
Output is correct |
44 |
Correct |
3 ms |
1576 KB |
Output is correct |
45 |
Correct |
65 ms |
18048 KB |
Output is correct |
46 |
Correct |
1 ms |
304 KB |
Output is correct |
47 |
Correct |
0 ms |
212 KB |
Output is correct |
48 |
Correct |
1 ms |
212 KB |
Output is correct |
49 |
Correct |
45 ms |
8248 KB |
Output is correct |
50 |
Correct |
156 ms |
27980 KB |
Output is correct |
51 |
Correct |
158 ms |
27956 KB |
Output is correct |
52 |
Correct |
158 ms |
27996 KB |
Output is correct |
53 |
Correct |
76 ms |
18092 KB |
Output is correct |
54 |
Correct |
62 ms |
18056 KB |
Output is correct |
55 |
Correct |
167 ms |
27928 KB |
Output is correct |
56 |
Correct |
162 ms |
28000 KB |
Output is correct |
57 |
Correct |
76 ms |
18048 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 |
8176 KB |
Output is correct |
62 |
Correct |
156 ms |
26668 KB |
Output is correct |
63 |
Correct |
159 ms |
26828 KB |
Output is correct |
64 |
Correct |
159 ms |
26612 KB |
Output is correct |
65 |
Correct |
1 ms |
212 KB |
Output is correct |
66 |
Correct |
39 ms |
8140 KB |
Output is correct |
67 |
Correct |
156 ms |
26616 KB |
Output is correct |
68 |
Correct |
156 ms |
26620 KB |
Output is correct |
69 |
Correct |
165 ms |
26680 KB |
Output is correct |
70 |
Correct |
1 ms |
212 KB |
Output is correct |
71 |
Correct |
0 ms |
340 KB |
Output is correct |
72 |
Incorrect |
1 ms |
340 KB |
Too many ways to get from 0 to 4, should be 1 found no less than 2 |
73 |
Halted |
0 ms |
0 KB |
- |