//In heads make different sets of heads
#include "supertrees.h"
#include <vector>
#include <set>
#include <iostream>
using namespace std;
vector<int> parent(1003);
vector<int> header_parent(1003);
vector<set<int>> header_counter;
int find_head(int n){
if(parent[n] == n){
return n;
}return find_head(parent[n]);
}
int find_head_parent(int n){
if(header_parent[n] == n){
return n;
}return find_head_parent(header_parent[n]);
}
int construct(std::vector<std::vector<int>> p) {
int n = p.size();
vector<vector<int>>ans(n,vector<int>(n,0));
set<int> a;
for (int i = 0; i < n; i++) {
parent[i] = i;
header_parent[i] = i;
header_counter.push_back(a);
}
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);
header_parent[higher] = parent[higher];
}
}
}
}
// cout <<"process 2" << endl;
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
if(i==j)
continue;
if(p[i][j] == 2){
int lower = min(i,j);
int higher = max(i,j);
ans[i][j] = 1;
ans[j][i] = 1;
header_parent[higher] = find_head_parent(lower);
header_counter[header_parent[higher]].insert(higher);
// cout << i << " " << j << " " << header_parent[higher] << " " << header_counter[header_parent[higher]].size() << endl;
}
}
}
// cout << "headers connected" << endl;
// cout << endl;
// for (int i = 0; i < n; i++) {
// cout << i << " " << parent[i] << " " << header_parent[i] << " " << header_counter[i].size() << endl;
// }
// cout << 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);
int i_head_header = find_head_parent(i_head);
int j_head_header = find_head_parent(j_head);
if(i==j)
continue;
if(p[i][j] == 0){
if(i_head == j_head){
return 0;
}
if(i_head_header == j_head_header){
return 0;
}
}else if(p[i][j] == 1){
if(i_head != j_head){
return 0;
}
}else if(p[i][j] == 2){
// cout << i << " " << j << " " << i_head_header << " " << j_head_header << endl;
if((header_counter[i_head_header].size() < 2)){
return 0;
}
if(i_head == j_head){
return 0;
}
if(i_head_header != j_head_header){
return 0;
}
}
}
}
build(ans);
return 1;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
7 ms |
1236 KB |
Output is correct |
7 |
Correct |
165 ms |
23032 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
7 ms |
1236 KB |
Output is correct |
7 |
Correct |
165 ms |
23032 KB |
Output is correct |
8 |
Correct |
1 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 |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
7 ms |
1248 KB |
Output is correct |
13 |
Correct |
155 ms |
23028 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
304 KB |
Output is correct |
16 |
Correct |
4 ms |
832 KB |
Output is correct |
17 |
Correct |
83 ms |
13036 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
40 ms |
6184 KB |
Output is correct |
21 |
Correct |
166 ms |
22820 KB |
Output is correct |
22 |
Correct |
159 ms |
22860 KB |
Output is correct |
23 |
Correct |
167 ms |
22804 KB |
Output is correct |
24 |
Correct |
160 ms |
22832 KB |
Output is correct |
25 |
Correct |
73 ms |
12888 KB |
Output is correct |
26 |
Correct |
67 ms |
12964 KB |
Output is correct |
27 |
Correct |
169 ms |
22848 KB |
Output is correct |
28 |
Correct |
164 ms |
22796 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 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 |
1236 KB |
Output is correct |
9 |
Correct |
159 ms |
22532 KB |
Output is correct |
10 |
Incorrect |
1 ms |
212 KB |
Too many ways to get from 0 to 3, should be 2 found no less than 3 |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
40 ms |
6240 KB |
Output is correct |
5 |
Correct |
156 ms |
23076 KB |
Output is correct |
6 |
Correct |
158 ms |
23128 KB |
Output is correct |
7 |
Correct |
168 ms |
23120 KB |
Output is correct |
8 |
Incorrect |
1 ms |
212 KB |
Too many ways to get from 0 to 2, should be 2 found no less than 3 |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
7 ms |
1236 KB |
Output is correct |
7 |
Correct |
165 ms |
23032 KB |
Output is correct |
8 |
Correct |
1 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 |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
7 ms |
1248 KB |
Output is correct |
13 |
Correct |
155 ms |
23028 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
304 KB |
Output is correct |
16 |
Correct |
4 ms |
832 KB |
Output is correct |
17 |
Correct |
83 ms |
13036 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
40 ms |
6184 KB |
Output is correct |
21 |
Correct |
166 ms |
22820 KB |
Output is correct |
22 |
Correct |
159 ms |
22860 KB |
Output is correct |
23 |
Correct |
167 ms |
22804 KB |
Output is correct |
24 |
Correct |
160 ms |
22832 KB |
Output is correct |
25 |
Correct |
73 ms |
12888 KB |
Output is correct |
26 |
Correct |
67 ms |
12964 KB |
Output is correct |
27 |
Correct |
169 ms |
22848 KB |
Output is correct |
28 |
Correct |
164 ms |
22796 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
1 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 |
1236 KB |
Output is correct |
37 |
Correct |
159 ms |
22532 KB |
Output is correct |
38 |
Incorrect |
1 ms |
212 KB |
Too many ways to get from 0 to 3, should be 2 found no less than 3 |
39 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
7 ms |
1236 KB |
Output is correct |
7 |
Correct |
165 ms |
23032 KB |
Output is correct |
8 |
Correct |
1 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 |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
7 ms |
1248 KB |
Output is correct |
13 |
Correct |
155 ms |
23028 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
304 KB |
Output is correct |
16 |
Correct |
4 ms |
832 KB |
Output is correct |
17 |
Correct |
83 ms |
13036 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
40 ms |
6184 KB |
Output is correct |
21 |
Correct |
166 ms |
22820 KB |
Output is correct |
22 |
Correct |
159 ms |
22860 KB |
Output is correct |
23 |
Correct |
167 ms |
22804 KB |
Output is correct |
24 |
Correct |
160 ms |
22832 KB |
Output is correct |
25 |
Correct |
73 ms |
12888 KB |
Output is correct |
26 |
Correct |
67 ms |
12964 KB |
Output is correct |
27 |
Correct |
169 ms |
22848 KB |
Output is correct |
28 |
Correct |
164 ms |
22796 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
1 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 |
1236 KB |
Output is correct |
37 |
Correct |
159 ms |
22532 KB |
Output is correct |
38 |
Incorrect |
1 ms |
212 KB |
Too many ways to get from 0 to 3, should be 2 found no less than 3 |
39 |
Halted |
0 ms |
0 KB |
- |