#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;
#define debug(v) cout << #v << ": " << v << endl;
const int MAXN = 1e3+3;
int n;
vector<vector<int>> ans;
int rep[MAXN], sz[MAXN];
int find(int no){
if(rep[no] == no) return no;
return rep[no] = find(rep[no]);
}
void merge(int a, int b){
a = find(a), b = find(b);
if(sz[a] < sz[b]) swap(a, b);
sz[a] += sz[b];
rep[b] = a;
}
int construct(vector<vector<int>> p) {
n = p.size();
ans.assign(n, vector<int>(n, 0));
for(int i = 0; i < n; i++){
sz[i] = 1; rep[i] = i;
}
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
if(p[i][j] == 0) continue;
if(find(i) != find(j)){
merge(i, j);
ans[j][i] = ans[i][j] = 1;
}
}
}
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
if(p[i][j] == 0){
if(find(i)==find(j)) return 0;
}
}
}
build(ans);
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... |