#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]) {
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];
int style = 0;
for(int j = 0; j < (int)u.size(); j++) {
for(int k = 0; k < (int)u.size(); k++) {
if( i == j ) continue;
if( !p[ u[j] ][ u[k] ] ) return false;
style = p[ u[j] ][ u[k] ];
}
}
if(style == 1) {
for(int j = 0; j + 1 < (int)u.size(); j++) {
int l = j + 1;
b[ u[j] ][ u[l] ] = 1;
b[ u[l] ][ u[j] ] = 1;
}
} else if(style == 2) {
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... |