#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e3 + 10;
int parent[maxn];
vector<int> member[maxn];
int find (int u) {
if (parent[u] == u) return u;
return parent[u] = find(parent[u]);
}
void onion (int u, int v) {
u = find(u);
v = find(v);
if (u == v) return;
parent[u] = v;
for (auto c : member[u]) {
member[v].push_back(c);
}
}
int construct(vector<vector<int>> p) {
int n = p.size();
for (int i = 0; i < n; i++) {
parent[i] = i;
member[i].push_back(i);
}
vector<vector<int>> answer;
for (int i = 0; i < n; i++) {
vector<int> row(n, 0);
answer.push_back(row);
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (p[i][j] == 2) {
onion(i, j);
} else if (p[i][j] == 0) {
if (find(i) == find(j)) return 0;
}
}
}
for (int i = 0; i < n; i++) {
if (parent[i] != i) continue;
cout << parent[i] << ": ";
for (int j = 0; j < member[i].size(); j++) {
cout << member[i][j] << ' ';
}
cout << '\n';
for (int j = 0; j < member[i].size(); j++) {
int other = member[i][(j + 1) % (member[i].size())];
answer[member[i][j]][other] = 1;
answer[other][member[i][j]] = 1;
}
}
build(answer);
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... |