#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;
#define len(v) (int) (v.size())
int construct(vector<vector<int>> p) {
int n = len(p);
vector ans(n, vector(n, 0));
vector<int> anc(n, -1);
vector<vector<int>> child;
int k = 0;
for (int v = 0; v < n; v++) {
if (anc[v] != -1) continue;
anc[v] = k++;
child.push_back({});
for (int u = 0; u < n; u++) {
if (p[v][u] != 0) {
anc[u] = k - 1;
child[k - 1].push_back(u);
}
}
}
for (int v = 0; v < n; v++) {
for (int u = 0; u < n; u++) {
if (p[v][u] == 0) {
if (anc[v] == anc[u]) {
return 0;
}
}
else if (p[v][u] <= 2) {
if (anc[v] != anc[u]) {
return 0;
}
}
else {
return 0;
}
}
}
for (int i = 0; i < k; i++) {
for (int j = 0; j + 1 < len(child[i]); j++) {
int v = child[i][j];
int u = child[i][j + 1];
ans[v][u] = 1;
ans[u][v] = 1;
}
}
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... |