#include "supertrees.h"
#include <vector>
#include <iostream>
#define pb push_back
using namespace std;
int find_head(vector<int> a,int val){
if(a[val] == val)
return val;
return find_head(a,a[val]);
}
int find_leaf(vector<int> a,int val){
if(a[val] == val)
return val;
return find_leaf(a,a[val]);
}
int construct(vector<vector<int>> p) {
// cout << "started" << endl;
int n = p.size();
vector<vector<int>> ans;
vector<int> temp(n,0);
vector<int> head;
vector<int> leaf;
for (int i = 0; i < n; i++) {
ans.pb(temp);
head.pb(i);
leaf.pb(i);
}
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
if(p[i][j] == 1){
int c = min(i,j),d = max(i,j);
int h_c = find_head(head,c);
int h_d = find_head(head,d);
if(h_c != h_d){
ans[h_c][h_d] = 1;
ans[h_d][h_c] = 1;
}
head[h_d] = h_c;
leaf[h_c] = find_leaf(leaf,d);
}
}
}
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
int c = min(i,j),d = max(i,j);
int h_c = find_head(head,c);
int h_d = find_head(head,d);
if(p[i][j] == 0 and h_c == h_d){
return 0;
}
if(p[i][j] == 1 and h_c != h_d){
return 0;
}
}
}
build(ans);
// cout << "finish" << endl;
return 1;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
236 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
15 ms |
1180 KB |
Output is correct |
7 |
Correct |
777 ms |
22116 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
236 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
15 ms |
1180 KB |
Output is correct |
7 |
Correct |
777 ms |
22116 KB |
Output is correct |
8 |
Correct |
0 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 |
8 ms |
1232 KB |
Output is correct |
13 |
Correct |
286 ms |
22036 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
7 ms |
724 KB |
Output is correct |
17 |
Correct |
360 ms |
12172 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
94 ms |
5712 KB |
Output is correct |
21 |
Correct |
465 ms |
22032 KB |
Output is correct |
22 |
Correct |
367 ms |
22032 KB |
Output is correct |
23 |
Correct |
616 ms |
22060 KB |
Output is correct |
24 |
Correct |
312 ms |
22020 KB |
Output is correct |
25 |
Correct |
99 ms |
12108 KB |
Output is correct |
26 |
Correct |
65 ms |
12164 KB |
Output is correct |
27 |
Correct |
608 ms |
22016 KB |
Output is correct |
28 |
Correct |
343 ms |
22016 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
Incorrect |
0 ms |
212 KB |
Answer gives possible 1 while actual possible 0 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Too few ways to get from 0 to 1, should be 2 found 0 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
236 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
15 ms |
1180 KB |
Output is correct |
7 |
Correct |
777 ms |
22116 KB |
Output is correct |
8 |
Correct |
0 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 |
8 ms |
1232 KB |
Output is correct |
13 |
Correct |
286 ms |
22036 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
7 ms |
724 KB |
Output is correct |
17 |
Correct |
360 ms |
12172 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
94 ms |
5712 KB |
Output is correct |
21 |
Correct |
465 ms |
22032 KB |
Output is correct |
22 |
Correct |
367 ms |
22032 KB |
Output is correct |
23 |
Correct |
616 ms |
22060 KB |
Output is correct |
24 |
Correct |
312 ms |
22020 KB |
Output is correct |
25 |
Correct |
99 ms |
12108 KB |
Output is correct |
26 |
Correct |
65 ms |
12164 KB |
Output is correct |
27 |
Correct |
608 ms |
22016 KB |
Output is correct |
28 |
Correct |
343 ms |
22016 KB |
Output is correct |
29 |
Correct |
1 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 |
Incorrect |
0 ms |
212 KB |
Answer gives possible 1 while actual possible 0 |
33 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
236 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
15 ms |
1180 KB |
Output is correct |
7 |
Correct |
777 ms |
22116 KB |
Output is correct |
8 |
Correct |
0 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 |
8 ms |
1232 KB |
Output is correct |
13 |
Correct |
286 ms |
22036 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
7 ms |
724 KB |
Output is correct |
17 |
Correct |
360 ms |
12172 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
94 ms |
5712 KB |
Output is correct |
21 |
Correct |
465 ms |
22032 KB |
Output is correct |
22 |
Correct |
367 ms |
22032 KB |
Output is correct |
23 |
Correct |
616 ms |
22060 KB |
Output is correct |
24 |
Correct |
312 ms |
22020 KB |
Output is correct |
25 |
Correct |
99 ms |
12108 KB |
Output is correct |
26 |
Correct |
65 ms |
12164 KB |
Output is correct |
27 |
Correct |
608 ms |
22016 KB |
Output is correct |
28 |
Correct |
343 ms |
22016 KB |
Output is correct |
29 |
Correct |
1 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 |
Incorrect |
0 ms |
212 KB |
Answer gives possible 1 while actual possible 0 |
33 |
Halted |
0 ms |
0 KB |
- |