#include "supertrees.h"
#include <vector>
#include <set>
#include <iostream>
using namespace std;
vector<int> parent(1003);
int find_head(int n){
if(parent[n] == n){
return n;
}return find_head(parent[n]);
}
int construct(std::vector<std::vector<int>> p) {
int n = p.size();
set<int> heads;
vector<vector<int>>ans(n,vector<int>(n,0));
for (int i = 0; i < n; i++) {
parent[i] = i;
}
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
if(i==j)
continue;
if(p[i][j] == 3){
return 0;
}else if(p[i][j] == 1){
int lower = min(i,j);
int higher = max(i,j);
if(find_head(lower) != find_head(higher)){
ans[i][j] = 1;
ans[j][i] = 1;
parent[higher] = find_head(lower);
}
}
}
}
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
if(i==j)
continue;
if(p[i][j] == 2){
heads.insert(find_head(i));
heads.insert(find_head(j));
}
}
}
// cout << "table travers" << endl;
vector<int> header;
for (int i : heads) {
header.push_back(i);
}
int t = header.size();
// cout << t << " " << (0<(t-1)) << endl;
for (int i = 0; i < (t-1); i++) {
// cout << "for" << endl;
ans[header[i]][header[i+1]] = 1;
ans[header[i+1]][header[i]] = 1;
}
if(t > 2){
// cout << "comare" << endl;
ans[header[0]][header[t-1]] = 1;
ans[header[t-1]][header[0]] = 1;
}
// cout << "headers connected" << endl;
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
int i_head = find_head(i);
int j_head = find_head(j);
if(i==j)
continue;
if(p[i][j] == 0){
if(i_head == j_head){
return 0;
}
if((heads.count(i_head) == 1) and (heads.count(j_head) == 1)){
return 0;
}
}else if(p[i][j] == 1){
if(i_head != j_head){
return 0;
}
}else if(p[i][j] == 2){
if(t < 3){
return 0;
}
// if(i_head == j_head){
// return 0;
// }
// if((heads.count(i_head) == 0) or (heads.count(j_head) == 0)){
// return 0;
// }
}
}
}
build(ans);
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 |
212 KB |
Output is correct |
6 |
Correct |
7 ms |
1200 KB |
Output is correct |
7 |
Correct |
157 ms |
21936 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 |
212 KB |
Output is correct |
6 |
Correct |
7 ms |
1200 KB |
Output is correct |
7 |
Correct |
157 ms |
21936 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
7 ms |
1108 KB |
Output is correct |
13 |
Correct |
154 ms |
21948 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
3 ms |
724 KB |
Output is correct |
17 |
Correct |
73 ms |
12040 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
41 ms |
5768 KB |
Output is correct |
21 |
Correct |
187 ms |
22024 KB |
Output is correct |
22 |
Correct |
155 ms |
22036 KB |
Output is correct |
23 |
Correct |
164 ms |
22016 KB |
Output is correct |
24 |
Correct |
155 ms |
21936 KB |
Output is correct |
25 |
Correct |
70 ms |
12048 KB |
Output is correct |
26 |
Correct |
63 ms |
12040 KB |
Output is correct |
27 |
Correct |
166 ms |
22036 KB |
Output is correct |
28 |
Correct |
152 ms |
21964 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 |
212 KB |
Output is correct |
8 |
Correct |
7 ms |
1172 KB |
Output is correct |
9 |
Correct |
154 ms |
21932 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
8 ms |
1108 KB |
Output is correct |
13 |
Correct |
189 ms |
22064 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
5 ms |
724 KB |
Output is correct |
17 |
Correct |
100 ms |
12164 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Incorrect |
17 ms |
3220 KB |
Answer gives possible 0 while actual possible 1 |
22 |
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 |
42 ms |
5656 KB |
Output is correct |
5 |
Correct |
156 ms |
22040 KB |
Output is correct |
6 |
Correct |
156 ms |
21964 KB |
Output is correct |
7 |
Correct |
165 ms |
22024 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Incorrect |
18 ms |
3212 KB |
Answer gives possible 0 while actual possible 1 |
10 |
Halted |
0 ms |
0 KB |
- |
# |
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 |
212 KB |
Output is correct |
6 |
Correct |
7 ms |
1200 KB |
Output is correct |
7 |
Correct |
157 ms |
21936 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
7 ms |
1108 KB |
Output is correct |
13 |
Correct |
154 ms |
21948 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
3 ms |
724 KB |
Output is correct |
17 |
Correct |
73 ms |
12040 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
41 ms |
5768 KB |
Output is correct |
21 |
Correct |
187 ms |
22024 KB |
Output is correct |
22 |
Correct |
155 ms |
22036 KB |
Output is correct |
23 |
Correct |
164 ms |
22016 KB |
Output is correct |
24 |
Correct |
155 ms |
21936 KB |
Output is correct |
25 |
Correct |
70 ms |
12048 KB |
Output is correct |
26 |
Correct |
63 ms |
12040 KB |
Output is correct |
27 |
Correct |
166 ms |
22036 KB |
Output is correct |
28 |
Correct |
152 ms |
21964 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 |
212 KB |
Output is correct |
36 |
Correct |
7 ms |
1172 KB |
Output is correct |
37 |
Correct |
154 ms |
21932 KB |
Output is correct |
38 |
Correct |
0 ms |
212 KB |
Output is correct |
39 |
Correct |
0 ms |
212 KB |
Output is correct |
40 |
Correct |
8 ms |
1108 KB |
Output is correct |
41 |
Correct |
189 ms |
22064 KB |
Output is correct |
42 |
Correct |
0 ms |
212 KB |
Output is correct |
43 |
Correct |
0 ms |
212 KB |
Output is correct |
44 |
Correct |
5 ms |
724 KB |
Output is correct |
45 |
Correct |
100 ms |
12164 KB |
Output is correct |
46 |
Correct |
1 ms |
212 KB |
Output is correct |
47 |
Correct |
1 ms |
212 KB |
Output is correct |
48 |
Correct |
0 ms |
212 KB |
Output is correct |
49 |
Incorrect |
17 ms |
3220 KB |
Answer gives possible 0 while actual possible 1 |
50 |
Halted |
0 ms |
0 KB |
- |
# |
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 |
212 KB |
Output is correct |
6 |
Correct |
7 ms |
1200 KB |
Output is correct |
7 |
Correct |
157 ms |
21936 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
7 ms |
1108 KB |
Output is correct |
13 |
Correct |
154 ms |
21948 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
3 ms |
724 KB |
Output is correct |
17 |
Correct |
73 ms |
12040 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
41 ms |
5768 KB |
Output is correct |
21 |
Correct |
187 ms |
22024 KB |
Output is correct |
22 |
Correct |
155 ms |
22036 KB |
Output is correct |
23 |
Correct |
164 ms |
22016 KB |
Output is correct |
24 |
Correct |
155 ms |
21936 KB |
Output is correct |
25 |
Correct |
70 ms |
12048 KB |
Output is correct |
26 |
Correct |
63 ms |
12040 KB |
Output is correct |
27 |
Correct |
166 ms |
22036 KB |
Output is correct |
28 |
Correct |
152 ms |
21964 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 |
212 KB |
Output is correct |
36 |
Correct |
7 ms |
1172 KB |
Output is correct |
37 |
Correct |
154 ms |
21932 KB |
Output is correct |
38 |
Correct |
0 ms |
212 KB |
Output is correct |
39 |
Correct |
0 ms |
212 KB |
Output is correct |
40 |
Correct |
8 ms |
1108 KB |
Output is correct |
41 |
Correct |
189 ms |
22064 KB |
Output is correct |
42 |
Correct |
0 ms |
212 KB |
Output is correct |
43 |
Correct |
0 ms |
212 KB |
Output is correct |
44 |
Correct |
5 ms |
724 KB |
Output is correct |
45 |
Correct |
100 ms |
12164 KB |
Output is correct |
46 |
Correct |
1 ms |
212 KB |
Output is correct |
47 |
Correct |
1 ms |
212 KB |
Output is correct |
48 |
Correct |
0 ms |
212 KB |
Output is correct |
49 |
Incorrect |
17 ms |
3220 KB |
Answer gives possible 0 while actual possible 1 |
50 |
Halted |
0 ms |
0 KB |
- |