#include "supertrees.h"
#include <bits/stdc++.h>
//#include "grader.cpp"
using namespace std;
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
struct DSU{
vi parent, size;
void init(int n){
for(int i = 0; i < n; i++){
parent.pb(i);
size.pb(1);
}
}
int find_parent(int v){
if(parent[v] == v) return v;
return parent[v] = find_parent(parent[v]);
}
void merge(int a, int b){
a = find_parent(a);
b = find_parent(b);
if(a != b){
if(size[b] > size[a])
swap(a, b);
parent[b] = a;
size[a] += size[b];
}
}
};
int construct(vector<vi> p) {
int n = p.size();
vector<vi> answer;
bool possible = true;
for(int i = 0; i < n; i++){
for(auto t : p[i]){
if(t == 3) possible = false;
}
}
for(int i = 0; i < n; i++){
vi pom(n,0);
answer.pb(pom);
}
DSU dsu;
dsu.init(n);
for(int i = 0; i < n; i++){
for(int j = i+1; j < n; j++){
if(p[i][j] == 1){
dsu.merge(i, j);
dsu.merge(j, i);
}
else
continue;
}
}
for(int i = 0; i < n; i++){
for(int j = i + 1; j < n; j++){
if(p[i][j] == 0 && dsu.find_parent(i) == dsu.find_parent(j)){
possible = false;
}
}
}
int last[n];
memset(last, -1, sizeof last);
for(int i = 0; i < n; i++){
int a = dsu.find_parent(i);
if(last[a] == -1) last[a] = i;
else{
answer[i][last[a]] = 1;
answer[last[a]][i] = 1;
last[a] = i;
}
}
if(!possible) return 0;
build(answer);
return 1;
}
# |
결과 |
실행 시간 |
메모리 |
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 |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
10 ms |
1108 KB |
Output is correct |
7 |
Correct |
147 ms |
22024 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
10 ms |
1108 KB |
Output is correct |
7 |
Correct |
147 ms |
22024 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 |
10 ms |
1172 KB |
Output is correct |
13 |
Correct |
143 ms |
21976 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
3 ms |
792 KB |
Output is correct |
17 |
Correct |
69 ms |
14056 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
37 ms |
6156 KB |
Output is correct |
21 |
Correct |
155 ms |
23936 KB |
Output is correct |
22 |
Correct |
169 ms |
24016 KB |
Output is correct |
23 |
Correct |
159 ms |
23920 KB |
Output is correct |
24 |
Correct |
152 ms |
23924 KB |
Output is correct |
25 |
Correct |
60 ms |
14072 KB |
Output is correct |
26 |
Correct |
63 ms |
14080 KB |
Output is correct |
27 |
Correct |
150 ms |
23928 KB |
Output is correct |
28 |
Correct |
146 ms |
23944 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 |
1 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 |
1 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 |
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 |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
10 ms |
1108 KB |
Output is correct |
7 |
Correct |
147 ms |
22024 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 |
10 ms |
1172 KB |
Output is correct |
13 |
Correct |
143 ms |
21976 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
3 ms |
792 KB |
Output is correct |
17 |
Correct |
69 ms |
14056 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
37 ms |
6156 KB |
Output is correct |
21 |
Correct |
155 ms |
23936 KB |
Output is correct |
22 |
Correct |
169 ms |
24016 KB |
Output is correct |
23 |
Correct |
159 ms |
23920 KB |
Output is correct |
24 |
Correct |
152 ms |
23924 KB |
Output is correct |
25 |
Correct |
60 ms |
14072 KB |
Output is correct |
26 |
Correct |
63 ms |
14080 KB |
Output is correct |
27 |
Correct |
150 ms |
23928 KB |
Output is correct |
28 |
Correct |
146 ms |
23944 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
0 ms |
212 KB |
Output is correct |
31 |
Correct |
1 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 |
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 |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
10 ms |
1108 KB |
Output is correct |
7 |
Correct |
147 ms |
22024 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 |
10 ms |
1172 KB |
Output is correct |
13 |
Correct |
143 ms |
21976 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
3 ms |
792 KB |
Output is correct |
17 |
Correct |
69 ms |
14056 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
37 ms |
6156 KB |
Output is correct |
21 |
Correct |
155 ms |
23936 KB |
Output is correct |
22 |
Correct |
169 ms |
24016 KB |
Output is correct |
23 |
Correct |
159 ms |
23920 KB |
Output is correct |
24 |
Correct |
152 ms |
23924 KB |
Output is correct |
25 |
Correct |
60 ms |
14072 KB |
Output is correct |
26 |
Correct |
63 ms |
14080 KB |
Output is correct |
27 |
Correct |
150 ms |
23928 KB |
Output is correct |
28 |
Correct |
146 ms |
23944 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
0 ms |
212 KB |
Output is correct |
31 |
Correct |
1 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 |
- |