#include "supertrees.h"
#include<bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
using namespace std;
const int maxn = 1e3 + 10;
vector<int> cnt[maxn];
struct DSU{
vector<int> pt, sz;
DSU(int sz0){
pt.resize(sz0);
sz.resize(sz0, 1);
for(int i = 0; i < sz0; i++){
pt[i] = i;
}
}
int find(int x){
if(x == pt[x]) return x;
else{
return pt[x] = find(pt[x]);
}
}
void unite(int u, int v){
int a = find(u);
int b = find(v);
if(a != b){
if(sz[a] < sz[b]) swap(a, b);
pt[b] = a;
sz[a] += sz[b];
for(auto v : cnt[b]){
cnt[a].push_back(v);
}
}
}
bool smcomp(int u, int v){
return find(u) == find(v);
}
};
int construct(vector<vector<int>> p){
int n = p.size();
vector<vector<int>> T(n, vector<int>(n));
for(int i = 0; i < n; i++){
cnt[i].push_back(i);
}
DSU dsu(n);
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
if(p[i][j] > 0 && dsu.find(i) != dsu.find(j)){
dsu.unite(i, j);
T[i][j] = 1;
T[j][i] = 1;
}
}
}
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
if(p[i][j] != 1 && dsu.find(i) == dsu.find(j)){
return 0;
}
}
}
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
if(p[i][j] == 3 || (dsu.find(i) == dsu.find(j) && p[i][j] == 0)){
return 0;
}
}
}
for(int i = 0; i < n; i++){
cnt[i].clear();
}
for(int i = 0; i < n; i++){
cnt[dsu.find(i)].push_back(i);
}
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
if(dsu.find(i) != dsu.find(j) && p[i][j] == 2){
dsu.unite(i, j);
}
}
}
for(int i = 0; i < n; i++){
if(cnt[i].size() < 2) continue;
if(cnt[i].size() == 2) return 0;
for(int j = 0; j < cnt[i].size(); j++){
int u = cnt[i][j];
int v = cnt[i][(j+1) % cnt[i].size()];
T[u][v] = T[v][u] = 1;
}
}
build(T);
return 1;
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |