#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_size(int v){
return size[v];
}
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(n, vi(n, 0));
DSU dsu;
dsu.init(n);
for(int i = 0; i < n; i++){
for(int j = i + 1; j < n; j++){
if(p[i][j] == 2){
dsu.merge(i, j);
dsu.merge(j, i);
}
}
}
for(int i = 0; i < n; i++){
for(int j = i + 1; j < n; j++){
if(dsu.find_parent(i) == dsu.find_parent(j) && p[i][j] == 0) return 0;
}
}
bool done[n];
memset(done, false, sizeof done);
for(int i = 0; i < n; i++){
if(done[dsu.find_parent(i)]) continue;
if(dsu.find_size(dsu.find_parent(i)) == 1) continue;
if(dsu.find_size(dsu.find_parent(i)) == 2) return 0;
done[dsu.find_parent(i)] = true;
int first = -1, last = -1;
for(int j = 0; j < n; j++){
if(dsu.find_parent(j) == dsu.find_parent(i)){
if(last == -1){
last = j;
first = j;
continue;
}
answer[j][last] = 1;
answer[last][j] = 1;
last = j;
}
}
answer[first][last] = 1;
answer[last][first] = 1;
}
build(answer);
return 1;
}
# |
결과 |
실행 시간 |
메모리 |
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 1 found 0 |
3 |
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 1 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 |
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 |
6 ms |
1108 KB |
Output is correct |
9 |
Correct |
158 ms |
21960 KB |
Output is correct |
10 |
Correct |
0 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 |
158 ms |
22008 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
4 ms |
724 KB |
Output is correct |
17 |
Correct |
72 ms |
12092 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
44 ms |
5772 KB |
Output is correct |
22 |
Correct |
152 ms |
23980 KB |
Output is correct |
23 |
Correct |
164 ms |
24020 KB |
Output is correct |
24 |
Correct |
165 ms |
23924 KB |
Output is correct |
25 |
Correct |
60 ms |
14064 KB |
Output is correct |
26 |
Correct |
80 ms |
14156 KB |
Output is correct |
27 |
Correct |
152 ms |
23924 KB |
Output is correct |
28 |
Correct |
160 ms |
24012 KB |
Output is correct |
29 |
Correct |
75 ms |
14064 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 |
Incorrect |
0 ms |
212 KB |
Too few ways to get from 1 to 2, should be 1 found 0 |
4 |
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 1 found 0 |
3 |
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 1 found 0 |
3 |
Halted |
0 ms |
0 KB |
- |