#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;
const int N = 1000;
bool is_add[N];
int tree_parent[N], circular_parent[N];
int find_tree_parent(int u) {
return tree_parent[u] = (u == tree_parent[u])
? u
: find_tree_parent(tree_parent[u]);
}
int find_circular_parent(int u) {
return circular_parent[u] = (u == circular_parent[u])
? u
: find_circular_parent(circular_parent[u]);
}
int construct(vector<vector<int>> p) {
int n = p.size();
vector<vector<int>> ans(n, vector<int>(n));
for (int i=0 ; i<n ; i++) {
for (int j=0 ; j<n ; j++) {
if (p[i][j] == 3) {
return 0;
}
}
}
for (int i=0 ; i<n ; i++) {
tree_parent[i] = i;
circular_parent[i] = i;
}
for (int i=0 ; i<n ; i++) {
for (int j=i+1 ; j<n ; j++) {
if (p[i][j] == 1) {
int ii = find_tree_parent(i);
int jj = find_tree_parent(j);
if (ii != jj) {
tree_parent[ii] = jj;
ans[i][j] = ans[j][i] = 1;
}
}
}
}
for (int i=0 ; i<n ; i++) {
for (int j=i+1 ; j<n ; j++) {
int ii = find_tree_parent(i);
int jj = find_tree_parent(j);
if (p[i][j] != 1 && ii == jj) {
return 0;
}
}
}
for (int i=0 ; i<n ; i++) {
for (int j=i+1 ; j<n ; j++) {
if (p[i][j] == 2) {
int ii = find_circular_parent(find_tree_parent(i));
int jj = find_circular_parent(find_tree_parent(j));
circular_parent[ii] = jj;
}
}
}
vector<int> group[N];
for (int i=0 ; i<n ; i++) {
int tree_i = find_tree_parent(i);
if (is_add[tree_i]) continue;
is_add[tree_i] = true;
int circular_i = find_circular_parent(tree_i);
group[circular_i].push_back(tree_i);
}
for (int i=0 ; i<N ; i++) {
int sz = group[i].size();
if (sz <= 1) {
continue;
}
else if (sz == 2) {
return 0;
}
else {
for (int j=0 ; j<sz-1 ; j++) {
ans[group[i][j]][group[i][j+1]] = ans[group[i][j+1]][group[i][j]] = 1;
}
ans[group[i][0]][group[i][sz-1]] = ans[group[i][sz-1]][group[i][0]] = 1;
}
}
build(ans);
return 1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
6 ms |
1216 KB |
Output is correct |
7 |
Correct |
123 ms |
24148 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
6 ms |
1216 KB |
Output is correct |
7 |
Correct |
123 ms |
24148 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
600 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
10 ms |
1372 KB |
Output is correct |
13 |
Correct |
120 ms |
24144 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
4 ms |
968 KB |
Output is correct |
17 |
Correct |
68 ms |
14160 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
31 ms |
6280 KB |
Output is correct |
21 |
Correct |
118 ms |
24148 KB |
Output is correct |
22 |
Correct |
120 ms |
24076 KB |
Output is correct |
23 |
Correct |
135 ms |
24148 KB |
Output is correct |
24 |
Correct |
112 ms |
23948 KB |
Output is correct |
25 |
Correct |
51 ms |
14160 KB |
Output is correct |
26 |
Correct |
56 ms |
14016 KB |
Output is correct |
27 |
Correct |
131 ms |
24060 KB |
Output is correct |
28 |
Correct |
112 ms |
24184 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
6 ms |
1372 KB |
Output is correct |
9 |
Correct |
133 ms |
24096 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
5 ms |
1192 KB |
Output is correct |
13 |
Correct |
117 ms |
24180 KB |
Output is correct |
14 |
Incorrect |
0 ms |
348 KB |
Answer gives possible 1 while actual possible 0 |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
28 ms |
6340 KB |
Output is correct |
5 |
Correct |
121 ms |
24096 KB |
Output is correct |
6 |
Correct |
134 ms |
24052 KB |
Output is correct |
7 |
Correct |
123 ms |
24080 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
29 ms |
6308 KB |
Output is correct |
10 |
Correct |
117 ms |
24144 KB |
Output is correct |
11 |
Correct |
118 ms |
24144 KB |
Output is correct |
12 |
Correct |
120 ms |
24148 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
31 ms |
6232 KB |
Output is correct |
17 |
Correct |
114 ms |
24100 KB |
Output is correct |
18 |
Correct |
118 ms |
24144 KB |
Output is correct |
19 |
Correct |
119 ms |
24144 KB |
Output is correct |
20 |
Correct |
116 ms |
23988 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
6 ms |
1216 KB |
Output is correct |
7 |
Correct |
123 ms |
24148 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
600 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
10 ms |
1372 KB |
Output is correct |
13 |
Correct |
120 ms |
24144 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
4 ms |
968 KB |
Output is correct |
17 |
Correct |
68 ms |
14160 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
31 ms |
6280 KB |
Output is correct |
21 |
Correct |
118 ms |
24148 KB |
Output is correct |
22 |
Correct |
120 ms |
24076 KB |
Output is correct |
23 |
Correct |
135 ms |
24148 KB |
Output is correct |
24 |
Correct |
112 ms |
23948 KB |
Output is correct |
25 |
Correct |
51 ms |
14160 KB |
Output is correct |
26 |
Correct |
56 ms |
14016 KB |
Output is correct |
27 |
Correct |
131 ms |
24060 KB |
Output is correct |
28 |
Correct |
112 ms |
24184 KB |
Output is correct |
29 |
Correct |
0 ms |
344 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
1 ms |
344 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
6 ms |
1372 KB |
Output is correct |
37 |
Correct |
133 ms |
24096 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
5 ms |
1192 KB |
Output is correct |
41 |
Correct |
117 ms |
24180 KB |
Output is correct |
42 |
Incorrect |
0 ms |
348 KB |
Answer gives possible 1 while actual possible 0 |
43 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
6 ms |
1216 KB |
Output is correct |
7 |
Correct |
123 ms |
24148 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
600 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
10 ms |
1372 KB |
Output is correct |
13 |
Correct |
120 ms |
24144 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
4 ms |
968 KB |
Output is correct |
17 |
Correct |
68 ms |
14160 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
31 ms |
6280 KB |
Output is correct |
21 |
Correct |
118 ms |
24148 KB |
Output is correct |
22 |
Correct |
120 ms |
24076 KB |
Output is correct |
23 |
Correct |
135 ms |
24148 KB |
Output is correct |
24 |
Correct |
112 ms |
23948 KB |
Output is correct |
25 |
Correct |
51 ms |
14160 KB |
Output is correct |
26 |
Correct |
56 ms |
14016 KB |
Output is correct |
27 |
Correct |
131 ms |
24060 KB |
Output is correct |
28 |
Correct |
112 ms |
24184 KB |
Output is correct |
29 |
Correct |
0 ms |
344 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
1 ms |
344 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
6 ms |
1372 KB |
Output is correct |
37 |
Correct |
133 ms |
24096 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
5 ms |
1192 KB |
Output is correct |
41 |
Correct |
117 ms |
24180 KB |
Output is correct |
42 |
Incorrect |
0 ms |
348 KB |
Answer gives possible 1 while actual possible 0 |
43 |
Halted |
0 ms |
0 KB |
- |