#include "supertrees.h"
#include <vector>
#include <bits/stdc++.h>
using namespace std;
struct dsu{
int n;
vector<int> size, parent;
dsu(int _n) : n(_n), size(n, 1), parent(n){
iota(parent.begin(), parent.end(), 0);
}
int get(int a){
return a == parent[a] ? a : parent[a] = get(parent[a]);
}
bool unite(int b, int a){
a = get(a);
b = get(b);
if(a == b){
return 0;
}
size[b] += size[a];
parent[a] = b;
return 1;
}
};
int construct(vector<vector<int>> a){
int n = a.size();
vector<int> cnt(n);
vector<vector<int>> ans(n, vector<int>(n, 0));
vector<vector<int>> v1(n),v2(n);
for(int i = 0; i < n; i++){
for(int j = i + 1; j < n; j++){
if(a[i][j] == 1){
v1[i].push_back(j);
v1[j].push_back(i);
} else if(a[i][j] == 2){
v2[i].push_back(j);
v2[j].push_back(i);
} else if(a[i][j] == 3){
return 0;
}
}
}
dsu s(n);
for(int i = 0; i < n; i++){
if(s.parent[i] == i){
for(int j = 0; j < n; j++){
for(int k : v1[i]){
if(a[k][j] != a[i][j]){
return 0;
}
ans[i][k] = 1;
ans[k][i] = 1;
cnt[i] += 1;
cnt[k] += 1;
s.unite(i, k);
}
}
}
}
vector<bool> b(n, false);
for(int i = 0; i < n; i++){
if(s.parent[i] != i || b[s.parent[i]]){
continue;
}
b[i] = true;
int cur = i;
for(int j : v2[i]){
if(s.parent[j] != j){
if(a[i][s.parent[j]] != 2){
return 0;
}
continue;
}
for(int k : v2[j]){
if((a[i][k] != 1 && s.parent[k] == i) || (a[i][k] == 1 && s.parent[k] != i)){
return 0;
}
}
ans[cur][j] = 1;
ans[j][cur] = 1;
cnt[cur] += 1;
cnt[j] += 1;
b[j] = true;
cur = j;
}
if(cur == i){
continue;
}
if(ans[i][cur]){
return 0;
}
ans[i][cur] = 1;
ans[cur][i] = 1;
cnt[i] += 1;
cnt[cur] += 1;
}
for(int i = 0; i < n; i++){
if(cnt[i] != (s.parent[i] == i ? (int)v1[i].size() + (v2[i].empty() ? 0 : 2) : 1)){
return 0;
}
}
build(ans);
return 1;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Incorrect |
0 ms |
204 KB |
Answer gives possible 0 while actual possible 1 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Incorrect |
0 ms |
204 KB |
Answer gives possible 0 while actual possible 1 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
7 ms |
1100 KB |
Output is correct |
9 |
Correct |
169 ms |
22036 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
11 ms |
1372 KB |
Output is correct |
13 |
Correct |
179 ms |
26084 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
5 ms |
940 KB |
Output is correct |
17 |
Correct |
87 ms |
15196 KB |
Output is correct |
18 |
Incorrect |
0 ms |
204 KB |
Answer gives possible 1 while actual possible 0 |
19 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Incorrect |
0 ms |
204 KB |
Answer gives possible 0 while actual possible 1 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Incorrect |
0 ms |
204 KB |
Answer gives possible 0 while actual possible 1 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Incorrect |
0 ms |
204 KB |
Answer gives possible 0 while actual possible 1 |
3 |
Halted |
0 ms |
0 KB |
- |