#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;
int construct(std::vector<std::vector<int>> p) {
int n = p.size();
std::vector<std::vector<int>> answer;
for (int i = 0; i < n; i++) {
std::vector<int> row;
row.resize(n);
answer.push_back(row);
}
vector < bool > u(n);
vector < int > now;
vector < vector < int > > all;
int cur;
for (int i = 0; i < n; ++i) {
if (u[i]) {
continue;
}
now.clear();
for (int j = i; j < n; ++j) {
if (u[j] || p[i][j] != 1) {
continue;
}
now.push_back(j);
u[j] = 1;
}
for (auto v : now) {
for (auto u : now) {
if (p[v][u] != 1) {
return 0;
}
}
}
for (int j = 1; j < (int)(now.size()); ++j) {
answer[now[j - 1]][now[j]] = 1;
answer[now[j]][now[j - 1]] = 1;
}
all.push_back(now);
}
for (int i = 0; i < (int)(all.size()); ++i) {
for (int j = i + 1; j < (int)(all.size()); ++j) {
for (auto v : all[i]) {
for (auto u : all[j]) {
if (p[v][u] != p[all[i][0]][all[j][0]]) {
return 0;
}
}
}
}
}
int last;
for (int i = 0; i < n; ++i) {
u[i] = 0;
}
vector < int > c(n);
int it = 0;
for (int i = 0; i < (int)(all.size()); ++i) {
if (u[i]) {
continue;
}
cur = 1;
last = all[i].back();
now.clear();
for (auto j : all[i]) {
now.push_back(j);
}
for (int j = i + 1; j < (int)(all.size()); ++j) {
if (!u[j] && p[last][all[j].back()] == 2) {
answer[last][all[j].back()] = 1;
answer[all[j].back()][last] = 1;
last = all[j].back();
u[j] = 1;
++cur;
for (auto k : all[j]) {
now.push_back(k);
}
}
}
if (cur == 2) {
return 0;
}
++it;
for (auto u : now) {
c[u] = it;
// for (auto v : now) {
// if (u != v && p[u][v] != 2) {
// return 0;
// }
// }
}
for (auto u : now) {
for (int j = 0; j < n; ++j) {
if (c[j] != it && p[u][j]) {
return 0;
}
}
}
if (last != all[i].back()) {
answer[last][all[i].back()] = 1;
answer[all[i].back()][last] = 1;
}
}
build(answer);
return 1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Correct |
1 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 |
10 ms |
1176 KB |
Output is correct |
7 |
Correct |
239 ms |
22656 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Correct |
1 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 |
10 ms |
1176 KB |
Output is correct |
7 |
Correct |
239 ms |
22656 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
10 ms |
1228 KB |
Output is correct |
13 |
Correct |
251 ms |
22680 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
5 ms |
844 KB |
Output is correct |
17 |
Correct |
123 ms |
12692 KB |
Output is correct |
18 |
Correct |
1 ms |
300 KB |
Output is correct |
19 |
Correct |
1 ms |
292 KB |
Output is correct |
20 |
Correct |
62 ms |
6060 KB |
Output is correct |
21 |
Correct |
245 ms |
22680 KB |
Output is correct |
22 |
Correct |
243 ms |
22724 KB |
Output is correct |
23 |
Correct |
254 ms |
22888 KB |
Output is correct |
24 |
Correct |
278 ms |
22656 KB |
Output is correct |
25 |
Correct |
110 ms |
12688 KB |
Output is correct |
26 |
Correct |
107 ms |
12920 KB |
Output is correct |
27 |
Correct |
250 ms |
22788 KB |
Output is correct |
28 |
Correct |
260 ms |
22652 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
10 ms |
1100 KB |
Output is correct |
9 |
Correct |
260 ms |
22016 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
10 ms |
1100 KB |
Output is correct |
13 |
Correct |
261 ms |
22068 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
5 ms |
712 KB |
Output is correct |
17 |
Correct |
117 ms |
12160 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Correct |
78 ms |
5764 KB |
Output is correct |
22 |
Correct |
248 ms |
22084 KB |
Output is correct |
23 |
Correct |
248 ms |
22024 KB |
Output is correct |
24 |
Correct |
259 ms |
22156 KB |
Output is correct |
25 |
Correct |
106 ms |
12100 KB |
Output is correct |
26 |
Correct |
109 ms |
12164 KB |
Output is correct |
27 |
Correct |
251 ms |
22020 KB |
Output is correct |
28 |
Correct |
261 ms |
22028 KB |
Output is correct |
29 |
Correct |
111 ms |
12100 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 |
204 KB |
Output is correct |
4 |
Correct |
61 ms |
6056 KB |
Output is correct |
5 |
Correct |
266 ms |
22720 KB |
Output is correct |
6 |
Correct |
247 ms |
22656 KB |
Output is correct |
7 |
Correct |
251 ms |
22684 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
61 ms |
6160 KB |
Output is correct |
10 |
Correct |
252 ms |
22848 KB |
Output is correct |
11 |
Correct |
251 ms |
22724 KB |
Output is correct |
12 |
Correct |
250 ms |
22736 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
61 ms |
6084 KB |
Output is correct |
17 |
Correct |
246 ms |
22676 KB |
Output is correct |
18 |
Correct |
252 ms |
22724 KB |
Output is correct |
19 |
Correct |
250 ms |
22696 KB |
Output is correct |
20 |
Correct |
246 ms |
22740 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Correct |
1 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 |
10 ms |
1176 KB |
Output is correct |
7 |
Correct |
239 ms |
22656 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
10 ms |
1228 KB |
Output is correct |
13 |
Correct |
251 ms |
22680 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
5 ms |
844 KB |
Output is correct |
17 |
Correct |
123 ms |
12692 KB |
Output is correct |
18 |
Correct |
1 ms |
300 KB |
Output is correct |
19 |
Correct |
1 ms |
292 KB |
Output is correct |
20 |
Correct |
62 ms |
6060 KB |
Output is correct |
21 |
Correct |
245 ms |
22680 KB |
Output is correct |
22 |
Correct |
243 ms |
22724 KB |
Output is correct |
23 |
Correct |
254 ms |
22888 KB |
Output is correct |
24 |
Correct |
278 ms |
22656 KB |
Output is correct |
25 |
Correct |
110 ms |
12688 KB |
Output is correct |
26 |
Correct |
107 ms |
12920 KB |
Output is correct |
27 |
Correct |
250 ms |
22788 KB |
Output is correct |
28 |
Correct |
260 ms |
22652 KB |
Output is correct |
29 |
Correct |
1 ms |
204 KB |
Output is correct |
30 |
Correct |
1 ms |
204 KB |
Output is correct |
31 |
Correct |
1 ms |
204 KB |
Output is correct |
32 |
Correct |
1 ms |
204 KB |
Output is correct |
33 |
Correct |
0 ms |
204 KB |
Output is correct |
34 |
Correct |
1 ms |
204 KB |
Output is correct |
35 |
Correct |
1 ms |
204 KB |
Output is correct |
36 |
Correct |
10 ms |
1100 KB |
Output is correct |
37 |
Correct |
260 ms |
22016 KB |
Output is correct |
38 |
Correct |
1 ms |
204 KB |
Output is correct |
39 |
Correct |
1 ms |
204 KB |
Output is correct |
40 |
Correct |
10 ms |
1100 KB |
Output is correct |
41 |
Correct |
261 ms |
22068 KB |
Output is correct |
42 |
Correct |
1 ms |
204 KB |
Output is correct |
43 |
Correct |
1 ms |
204 KB |
Output is correct |
44 |
Correct |
5 ms |
712 KB |
Output is correct |
45 |
Correct |
117 ms |
12160 KB |
Output is correct |
46 |
Correct |
1 ms |
204 KB |
Output is correct |
47 |
Correct |
1 ms |
204 KB |
Output is correct |
48 |
Correct |
1 ms |
204 KB |
Output is correct |
49 |
Correct |
78 ms |
5764 KB |
Output is correct |
50 |
Correct |
248 ms |
22084 KB |
Output is correct |
51 |
Correct |
248 ms |
22024 KB |
Output is correct |
52 |
Correct |
259 ms |
22156 KB |
Output is correct |
53 |
Correct |
106 ms |
12100 KB |
Output is correct |
54 |
Correct |
109 ms |
12164 KB |
Output is correct |
55 |
Correct |
251 ms |
22020 KB |
Output is correct |
56 |
Correct |
261 ms |
22028 KB |
Output is correct |
57 |
Correct |
111 ms |
12100 KB |
Output is correct |
58 |
Correct |
1 ms |
204 KB |
Output is correct |
59 |
Correct |
1 ms |
204 KB |
Output is correct |
60 |
Correct |
7 ms |
864 KB |
Output is correct |
61 |
Correct |
107 ms |
14080 KB |
Output is correct |
62 |
Correct |
1 ms |
204 KB |
Output is correct |
63 |
Correct |
1 ms |
204 KB |
Output is correct |
64 |
Correct |
1 ms |
204 KB |
Output is correct |
65 |
Correct |
62 ms |
6252 KB |
Output is correct |
66 |
Correct |
106 ms |
14068 KB |
Output is correct |
67 |
Correct |
107 ms |
14076 KB |
Output is correct |
68 |
Correct |
106 ms |
14120 KB |
Output is correct |
69 |
Correct |
107 ms |
14060 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Correct |
1 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 |
10 ms |
1176 KB |
Output is correct |
7 |
Correct |
239 ms |
22656 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
10 ms |
1228 KB |
Output is correct |
13 |
Correct |
251 ms |
22680 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
5 ms |
844 KB |
Output is correct |
17 |
Correct |
123 ms |
12692 KB |
Output is correct |
18 |
Correct |
1 ms |
300 KB |
Output is correct |
19 |
Correct |
1 ms |
292 KB |
Output is correct |
20 |
Correct |
62 ms |
6060 KB |
Output is correct |
21 |
Correct |
245 ms |
22680 KB |
Output is correct |
22 |
Correct |
243 ms |
22724 KB |
Output is correct |
23 |
Correct |
254 ms |
22888 KB |
Output is correct |
24 |
Correct |
278 ms |
22656 KB |
Output is correct |
25 |
Correct |
110 ms |
12688 KB |
Output is correct |
26 |
Correct |
107 ms |
12920 KB |
Output is correct |
27 |
Correct |
250 ms |
22788 KB |
Output is correct |
28 |
Correct |
260 ms |
22652 KB |
Output is correct |
29 |
Correct |
1 ms |
204 KB |
Output is correct |
30 |
Correct |
1 ms |
204 KB |
Output is correct |
31 |
Correct |
1 ms |
204 KB |
Output is correct |
32 |
Correct |
1 ms |
204 KB |
Output is correct |
33 |
Correct |
0 ms |
204 KB |
Output is correct |
34 |
Correct |
1 ms |
204 KB |
Output is correct |
35 |
Correct |
1 ms |
204 KB |
Output is correct |
36 |
Correct |
10 ms |
1100 KB |
Output is correct |
37 |
Correct |
260 ms |
22016 KB |
Output is correct |
38 |
Correct |
1 ms |
204 KB |
Output is correct |
39 |
Correct |
1 ms |
204 KB |
Output is correct |
40 |
Correct |
10 ms |
1100 KB |
Output is correct |
41 |
Correct |
261 ms |
22068 KB |
Output is correct |
42 |
Correct |
1 ms |
204 KB |
Output is correct |
43 |
Correct |
1 ms |
204 KB |
Output is correct |
44 |
Correct |
5 ms |
712 KB |
Output is correct |
45 |
Correct |
117 ms |
12160 KB |
Output is correct |
46 |
Correct |
1 ms |
204 KB |
Output is correct |
47 |
Correct |
1 ms |
204 KB |
Output is correct |
48 |
Correct |
1 ms |
204 KB |
Output is correct |
49 |
Correct |
78 ms |
5764 KB |
Output is correct |
50 |
Correct |
248 ms |
22084 KB |
Output is correct |
51 |
Correct |
248 ms |
22024 KB |
Output is correct |
52 |
Correct |
259 ms |
22156 KB |
Output is correct |
53 |
Correct |
106 ms |
12100 KB |
Output is correct |
54 |
Correct |
109 ms |
12164 KB |
Output is correct |
55 |
Correct |
251 ms |
22020 KB |
Output is correct |
56 |
Correct |
261 ms |
22028 KB |
Output is correct |
57 |
Correct |
111 ms |
12100 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 |
204 KB |
Output is correct |
61 |
Correct |
61 ms |
6056 KB |
Output is correct |
62 |
Correct |
266 ms |
22720 KB |
Output is correct |
63 |
Correct |
247 ms |
22656 KB |
Output is correct |
64 |
Correct |
251 ms |
22684 KB |
Output is correct |
65 |
Correct |
1 ms |
204 KB |
Output is correct |
66 |
Correct |
61 ms |
6160 KB |
Output is correct |
67 |
Correct |
252 ms |
22848 KB |
Output is correct |
68 |
Correct |
251 ms |
22724 KB |
Output is correct |
69 |
Correct |
250 ms |
22736 KB |
Output is correct |
70 |
Correct |
1 ms |
204 KB |
Output is correct |
71 |
Correct |
1 ms |
204 KB |
Output is correct |
72 |
Correct |
1 ms |
204 KB |
Output is correct |
73 |
Correct |
61 ms |
6084 KB |
Output is correct |
74 |
Correct |
246 ms |
22676 KB |
Output is correct |
75 |
Correct |
252 ms |
22724 KB |
Output is correct |
76 |
Correct |
250 ms |
22696 KB |
Output is correct |
77 |
Correct |
246 ms |
22740 KB |
Output is correct |
78 |
Correct |
1 ms |
204 KB |
Output is correct |
79 |
Correct |
1 ms |
204 KB |
Output is correct |
80 |
Correct |
7 ms |
864 KB |
Output is correct |
81 |
Correct |
107 ms |
14080 KB |
Output is correct |
82 |
Correct |
1 ms |
204 KB |
Output is correct |
83 |
Correct |
1 ms |
204 KB |
Output is correct |
84 |
Correct |
1 ms |
204 KB |
Output is correct |
85 |
Correct |
62 ms |
6252 KB |
Output is correct |
86 |
Correct |
106 ms |
14068 KB |
Output is correct |
87 |
Correct |
107 ms |
14076 KB |
Output is correct |
88 |
Correct |
106 ms |
14120 KB |
Output is correct |
89 |
Correct |
107 ms |
14060 KB |
Output is correct |
90 |
Correct |
1 ms |
204 KB |
Output is correct |
91 |
Correct |
1 ms |
204 KB |
Output is correct |
92 |
Correct |
5 ms |
844 KB |
Output is correct |
93 |
Correct |
105 ms |
14076 KB |
Output is correct |
94 |
Correct |
1 ms |
204 KB |
Output is correct |
95 |
Correct |
1 ms |
204 KB |
Output is correct |
96 |
Correct |
1 ms |
204 KB |
Output is correct |
97 |
Correct |
28 ms |
3692 KB |
Output is correct |
98 |
Correct |
118 ms |
14064 KB |
Output is correct |
99 |
Correct |
106 ms |
14072 KB |
Output is correct |
100 |
Correct |
104 ms |
14072 KB |
Output is correct |
101 |
Correct |
114 ms |
14120 KB |
Output is correct |
102 |
Correct |
106 ms |
14020 KB |
Output is correct |
103 |
Correct |
106 ms |
14076 KB |
Output is correct |
104 |
Correct |
102 ms |
14088 KB |
Output is correct |
105 |
Correct |
131 ms |
14020 KB |
Output is correct |