#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;
// #define int long long
#define all(x) x.begin(), x.end()
#define pb push_back
#define ar array
#define nl '\n'
struct dsu {
vector<int> p, sz;
dsu(int n) : p(n), sz(n) {
iota(all(p), 0);
}
int find(int v) {
return v == p[v] ? v : p[v] = find(p[v]);
}
void unite(int u, int v) {
u = find(u), v = find(v);
if(u == v) return;
if(sz[u] < sz[v]) swap(u, v);
p[v] = u;
sz[u] += sz[v];
}
};
int construct(std::vector<std::vector<int>> p) {
int n = p.size();
dsu d(n);
for(int i = 0; i < n; i++) {
for(int j = 0; j < n; j++) {
if(p[i][j] == 1) {
d.unite(i, j);
}
}
}
vector<vector<int>> v(n);
vector<vector<int>> b(n, vector<int>(n));
for(int i = 0; i < n; i++) {
v[d.find(i)].pb(i);
}
for(int i = 0; i < n; i++) {
for(int j = 0; j < (int)v[i].size(); j++) {
for(int k = 0; k < (int)v[i].size(); k++) {
if( p[ v[i][j] ][ v[i][k] ] != 1 ) return false;
}
}
for(int j = 0; j + 1 < (int)v[i].size(); j++) {
b[ v[i][j] ][ v[i][j + 1] ] = 1;
b[ v[i][j + 1] ][ v[i][j] ] = 1;
}
}
build(b);
return true;
}
# | 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... |