#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++) {
auto &u = v[i];
for(int j = 0; j + 1 < (int)u.size(); j++) {
b[ u[j] ][ u[j + 1] ] = 1;
b[ u[j + 1] ][ u[j] ] = 1;
}
u.clear();
}
dsu d2(n);
for(int i = 0; i < n; i++) {
for(int j = 0; j < n; j++) {
if(p[i][j] == 2) {
d2.unite( d.find(i), d.find(j) );
}
}
}
for(int i = 0; i < n; i++) {
v[d2.find(i)].pb(i);
}
for(int i = 0; i < n; i++) {
auto &u = v[i];
// cout << i << ": ";
// for(auto &x : u) cout << x << ' ';
// cout << nl;
// assert(u.size() != 2);
if(u.size() == 2) return false;
if(u.size() <= 1) continue;
for(int j = 0; j < (int)u.size(); j++) {
int l = (j + 1 == (int)u.size() ? 0 : j + 1);
b[ u[j] ][ u[l] ] = 1;
b[ u[l] ][ u[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... |