#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
int n;
vector<vector<int> > answer;
void add_edge(int x, int y) {
answer[x][y] = 1;
answer[y][x] = 1;
}
void dfs(int cur, vector<vector<int> > &p, int &comp_cnt, vector<int> &comp, vector<int> &poss, int weight, vector<vector<int> > &by_comp) {
comp[cur] = comp_cnt;
by_comp[comp_cnt - 1].pb(cur);
for(int nei : poss) {
if(!comp[nei] && p[cur][nei] == weight) {
dfs(nei, p, comp_cnt, comp, poss, weight, by_comp);
}
}
}
int construct(vector<vector<int> > p) {
n = (int) p.size();
answer.assign(n, vector<int> (n, 0));
for(int i = 0; i < n; i++) {
for(int j = 0; j < n; j++) {
if(p[i][j] == 3) {
return 0;
}
}
}
int tree_cnt = 0;
vector<int> which_tree(n, 0);
vector<int> all(n, 0);
for(int i = 0; i < n; i++) {
all[i] = i;
}
vector<vector<int> > by_tree(n, vector<int> (0, 0));
for(int cur : all) {
if(!which_tree[cur]) {
tree_cnt++;
dfs(cur, p, tree_cnt, which_tree, all, 1, by_tree);
}
}
by_tree.resize(tree_cnt);
vector<int> rep(n, -1);
vector<int> list_reps;
for(vector<int> &tree : by_tree) {
list_reps.pb(tree[0]);
for(int &cur : tree) {
rep[cur] = tree[0];
}
for(int i = 0; i + 1 < (int) tree.size(); i++) {
add_edge(tree[i], tree[i + 1]);
}
for(int x : tree) {
for(int y : tree) {
if(x != y && p[x][y] != 1) {
return 0;
}
}
}
}
for(int x = 0; x < n; x++) {
for(int y = 0; y < n; y++) {
if(p[x][y] != p[rep[x]][rep[y]]) {
return 0;
}
}
}
int cycle_cnt = 0;
vector<int> which_cycle(n, 0);
vector<vector<int> > by_cycle(n, vector<int> (0, 0));
for(int cur : list_reps) {
if(!which_cycle[cur]) {
cycle_cnt++;
dfs(cur, p, cycle_cnt, which_cycle, list_reps, 2, by_cycle);
}
}
by_cycle.resize(cycle_cnt);
for(vector<int> &cycle : by_cycle) {
if((int) cycle.size() == 2) {
return 0;
}
if((int) cycle.size() != 1) {
for(int i = 0; i + 1 < (int) cycle.size(); i++) {
add_edge(cycle[i], cycle[i + 1]);
}
add_edge(cycle.back(), cycle[0]);
}
for(int x : cycle) {
for(int y : cycle) {
if(x != y && p[x][y] != 2) {
return 0;
}
}
}
}
build(answer);
return 1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
8 ms |
1236 KB |
Output is correct |
7 |
Correct |
179 ms |
24068 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
8 ms |
1236 KB |
Output is correct |
7 |
Correct |
179 ms |
24068 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
296 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
10 ms |
1236 KB |
Output is correct |
13 |
Correct |
178 ms |
24180 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
296 KB |
Output is correct |
16 |
Correct |
3 ms |
852 KB |
Output is correct |
17 |
Correct |
77 ms |
14208 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
43 ms |
6240 KB |
Output is correct |
21 |
Correct |
180 ms |
24140 KB |
Output is correct |
22 |
Correct |
186 ms |
24024 KB |
Output is correct |
23 |
Correct |
200 ms |
24088 KB |
Output is correct |
24 |
Correct |
172 ms |
24096 KB |
Output is correct |
25 |
Correct |
73 ms |
14080 KB |
Output is correct |
26 |
Correct |
71 ms |
14068 KB |
Output is correct |
27 |
Correct |
180 ms |
24104 KB |
Output is correct |
28 |
Correct |
179 ms |
24140 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
7 ms |
1180 KB |
Output is correct |
9 |
Correct |
239 ms |
24052 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
300 KB |
Output is correct |
12 |
Correct |
11 ms |
1236 KB |
Output is correct |
13 |
Correct |
169 ms |
24124 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
4 ms |
828 KB |
Output is correct |
17 |
Correct |
78 ms |
14192 KB |
Output is correct |
18 |
Correct |
1 ms |
300 KB |
Output is correct |
19 |
Correct |
1 ms |
300 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
44 ms |
6224 KB |
Output is correct |
22 |
Correct |
177 ms |
24048 KB |
Output is correct |
23 |
Correct |
181 ms |
24028 KB |
Output is correct |
24 |
Correct |
181 ms |
24140 KB |
Output is correct |
25 |
Correct |
70 ms |
14192 KB |
Output is correct |
26 |
Correct |
76 ms |
14156 KB |
Output is correct |
27 |
Correct |
178 ms |
24080 KB |
Output is correct |
28 |
Correct |
194 ms |
24076 KB |
Output is correct |
29 |
Correct |
79 ms |
14120 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
43 ms |
6264 KB |
Output is correct |
5 |
Correct |
176 ms |
23996 KB |
Output is correct |
6 |
Correct |
169 ms |
23980 KB |
Output is correct |
7 |
Correct |
179 ms |
24052 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
44 ms |
6212 KB |
Output is correct |
10 |
Correct |
184 ms |
24044 KB |
Output is correct |
11 |
Correct |
178 ms |
24180 KB |
Output is correct |
12 |
Correct |
176 ms |
24140 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
46 ms |
6252 KB |
Output is correct |
17 |
Correct |
179 ms |
24104 KB |
Output is correct |
18 |
Correct |
173 ms |
24012 KB |
Output is correct |
19 |
Correct |
172 ms |
24052 KB |
Output is correct |
20 |
Correct |
170 ms |
24120 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
8 ms |
1236 KB |
Output is correct |
7 |
Correct |
179 ms |
24068 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
296 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
10 ms |
1236 KB |
Output is correct |
13 |
Correct |
178 ms |
24180 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
296 KB |
Output is correct |
16 |
Correct |
3 ms |
852 KB |
Output is correct |
17 |
Correct |
77 ms |
14208 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
43 ms |
6240 KB |
Output is correct |
21 |
Correct |
180 ms |
24140 KB |
Output is correct |
22 |
Correct |
186 ms |
24024 KB |
Output is correct |
23 |
Correct |
200 ms |
24088 KB |
Output is correct |
24 |
Correct |
172 ms |
24096 KB |
Output is correct |
25 |
Correct |
73 ms |
14080 KB |
Output is correct |
26 |
Correct |
71 ms |
14068 KB |
Output is correct |
27 |
Correct |
180 ms |
24104 KB |
Output is correct |
28 |
Correct |
179 ms |
24140 KB |
Output is correct |
29 |
Correct |
0 ms |
212 KB |
Output is correct |
30 |
Correct |
1 ms |
212 KB |
Output is correct |
31 |
Correct |
1 ms |
212 KB |
Output is correct |
32 |
Correct |
1 ms |
212 KB |
Output is correct |
33 |
Correct |
1 ms |
212 KB |
Output is correct |
34 |
Correct |
1 ms |
212 KB |
Output is correct |
35 |
Correct |
1 ms |
212 KB |
Output is correct |
36 |
Correct |
7 ms |
1180 KB |
Output is correct |
37 |
Correct |
239 ms |
24052 KB |
Output is correct |
38 |
Correct |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
1 ms |
300 KB |
Output is correct |
40 |
Correct |
11 ms |
1236 KB |
Output is correct |
41 |
Correct |
169 ms |
24124 KB |
Output is correct |
42 |
Correct |
0 ms |
212 KB |
Output is correct |
43 |
Correct |
1 ms |
212 KB |
Output is correct |
44 |
Correct |
4 ms |
828 KB |
Output is correct |
45 |
Correct |
78 ms |
14192 KB |
Output is correct |
46 |
Correct |
1 ms |
300 KB |
Output is correct |
47 |
Correct |
1 ms |
300 KB |
Output is correct |
48 |
Correct |
1 ms |
212 KB |
Output is correct |
49 |
Correct |
44 ms |
6224 KB |
Output is correct |
50 |
Correct |
177 ms |
24048 KB |
Output is correct |
51 |
Correct |
181 ms |
24028 KB |
Output is correct |
52 |
Correct |
181 ms |
24140 KB |
Output is correct |
53 |
Correct |
70 ms |
14192 KB |
Output is correct |
54 |
Correct |
76 ms |
14156 KB |
Output is correct |
55 |
Correct |
178 ms |
24080 KB |
Output is correct |
56 |
Correct |
194 ms |
24076 KB |
Output is correct |
57 |
Correct |
79 ms |
14120 KB |
Output is correct |
58 |
Correct |
1 ms |
212 KB |
Output is correct |
59 |
Correct |
1 ms |
212 KB |
Output is correct |
60 |
Correct |
4 ms |
824 KB |
Output is correct |
61 |
Correct |
77 ms |
14200 KB |
Output is correct |
62 |
Correct |
1 ms |
212 KB |
Output is correct |
63 |
Correct |
1 ms |
296 KB |
Output is correct |
64 |
Correct |
1 ms |
212 KB |
Output is correct |
65 |
Correct |
46 ms |
6196 KB |
Output is correct |
66 |
Correct |
69 ms |
14156 KB |
Output is correct |
67 |
Correct |
76 ms |
14072 KB |
Output is correct |
68 |
Correct |
70 ms |
14072 KB |
Output is correct |
69 |
Correct |
69 ms |
14192 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
8 ms |
1236 KB |
Output is correct |
7 |
Correct |
179 ms |
24068 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
296 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
10 ms |
1236 KB |
Output is correct |
13 |
Correct |
178 ms |
24180 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
296 KB |
Output is correct |
16 |
Correct |
3 ms |
852 KB |
Output is correct |
17 |
Correct |
77 ms |
14208 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
43 ms |
6240 KB |
Output is correct |
21 |
Correct |
180 ms |
24140 KB |
Output is correct |
22 |
Correct |
186 ms |
24024 KB |
Output is correct |
23 |
Correct |
200 ms |
24088 KB |
Output is correct |
24 |
Correct |
172 ms |
24096 KB |
Output is correct |
25 |
Correct |
73 ms |
14080 KB |
Output is correct |
26 |
Correct |
71 ms |
14068 KB |
Output is correct |
27 |
Correct |
180 ms |
24104 KB |
Output is correct |
28 |
Correct |
179 ms |
24140 KB |
Output is correct |
29 |
Correct |
0 ms |
212 KB |
Output is correct |
30 |
Correct |
1 ms |
212 KB |
Output is correct |
31 |
Correct |
1 ms |
212 KB |
Output is correct |
32 |
Correct |
1 ms |
212 KB |
Output is correct |
33 |
Correct |
1 ms |
212 KB |
Output is correct |
34 |
Correct |
1 ms |
212 KB |
Output is correct |
35 |
Correct |
1 ms |
212 KB |
Output is correct |
36 |
Correct |
7 ms |
1180 KB |
Output is correct |
37 |
Correct |
239 ms |
24052 KB |
Output is correct |
38 |
Correct |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
1 ms |
300 KB |
Output is correct |
40 |
Correct |
11 ms |
1236 KB |
Output is correct |
41 |
Correct |
169 ms |
24124 KB |
Output is correct |
42 |
Correct |
0 ms |
212 KB |
Output is correct |
43 |
Correct |
1 ms |
212 KB |
Output is correct |
44 |
Correct |
4 ms |
828 KB |
Output is correct |
45 |
Correct |
78 ms |
14192 KB |
Output is correct |
46 |
Correct |
1 ms |
300 KB |
Output is correct |
47 |
Correct |
1 ms |
300 KB |
Output is correct |
48 |
Correct |
1 ms |
212 KB |
Output is correct |
49 |
Correct |
44 ms |
6224 KB |
Output is correct |
50 |
Correct |
177 ms |
24048 KB |
Output is correct |
51 |
Correct |
181 ms |
24028 KB |
Output is correct |
52 |
Correct |
181 ms |
24140 KB |
Output is correct |
53 |
Correct |
70 ms |
14192 KB |
Output is correct |
54 |
Correct |
76 ms |
14156 KB |
Output is correct |
55 |
Correct |
178 ms |
24080 KB |
Output is correct |
56 |
Correct |
194 ms |
24076 KB |
Output is correct |
57 |
Correct |
79 ms |
14120 KB |
Output is correct |
58 |
Correct |
0 ms |
212 KB |
Output is correct |
59 |
Correct |
1 ms |
212 KB |
Output is correct |
60 |
Correct |
0 ms |
212 KB |
Output is correct |
61 |
Correct |
43 ms |
6264 KB |
Output is correct |
62 |
Correct |
176 ms |
23996 KB |
Output is correct |
63 |
Correct |
169 ms |
23980 KB |
Output is correct |
64 |
Correct |
179 ms |
24052 KB |
Output is correct |
65 |
Correct |
1 ms |
212 KB |
Output is correct |
66 |
Correct |
44 ms |
6212 KB |
Output is correct |
67 |
Correct |
184 ms |
24044 KB |
Output is correct |
68 |
Correct |
178 ms |
24180 KB |
Output is correct |
69 |
Correct |
176 ms |
24140 KB |
Output is correct |
70 |
Correct |
1 ms |
212 KB |
Output is correct |
71 |
Correct |
1 ms |
212 KB |
Output is correct |
72 |
Correct |
0 ms |
212 KB |
Output is correct |
73 |
Correct |
46 ms |
6252 KB |
Output is correct |
74 |
Correct |
179 ms |
24104 KB |
Output is correct |
75 |
Correct |
173 ms |
24012 KB |
Output is correct |
76 |
Correct |
172 ms |
24052 KB |
Output is correct |
77 |
Correct |
170 ms |
24120 KB |
Output is correct |
78 |
Correct |
1 ms |
212 KB |
Output is correct |
79 |
Correct |
1 ms |
212 KB |
Output is correct |
80 |
Correct |
4 ms |
824 KB |
Output is correct |
81 |
Correct |
77 ms |
14200 KB |
Output is correct |
82 |
Correct |
1 ms |
212 KB |
Output is correct |
83 |
Correct |
1 ms |
296 KB |
Output is correct |
84 |
Correct |
1 ms |
212 KB |
Output is correct |
85 |
Correct |
46 ms |
6196 KB |
Output is correct |
86 |
Correct |
69 ms |
14156 KB |
Output is correct |
87 |
Correct |
76 ms |
14072 KB |
Output is correct |
88 |
Correct |
70 ms |
14072 KB |
Output is correct |
89 |
Correct |
69 ms |
14192 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 |
820 KB |
Output is correct |
93 |
Correct |
82 ms |
14064 KB |
Output is correct |
94 |
Correct |
0 ms |
212 KB |
Output is correct |
95 |
Correct |
1 ms |
212 KB |
Output is correct |
96 |
Correct |
1 ms |
304 KB |
Output is correct |
97 |
Correct |
23 ms |
3684 KB |
Output is correct |
98 |
Correct |
66 ms |
14028 KB |
Output is correct |
99 |
Correct |
67 ms |
14000 KB |
Output is correct |
100 |
Correct |
66 ms |
14068 KB |
Output is correct |
101 |
Correct |
76 ms |
14064 KB |
Output is correct |
102 |
Correct |
69 ms |
14064 KB |
Output is correct |
103 |
Correct |
71 ms |
14068 KB |
Output is correct |
104 |
Correct |
65 ms |
14076 KB |
Output is correct |
105 |
Correct |
102 ms |
14080 KB |
Output is correct |