#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 = 1e5;
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];
}
}
bool smcomp(int u, int v){
return find(u) == find(v);
}
};
int construct(vector<vector<int>> p){
int n = p.size();
DSU dsu(n);
vector<vector<int>> T(n, vector<int>(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;
}
}
}
vector<vector<int>> ps(n);
for(int i = 0; i < n; i++){
ps[dsu.find(i)].push_back(i);
}
for (int i = 0; i < n; i++) {
if (ps[i].empty()) continue;
for (int j = 1; j < (int)ps[i].size(); j++){
if(p[ps[i][0]][ps[i][j]] == 0){
return 0;
}
int u = ps[i][0];
int v = ps[i][j];
T[u][v] = 1;
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... |