This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#include "supertrees.h"
using namespace std;
int construct(vector<vector<int>> p) {
vector<vector<int>> b(p.size(), vector<int>(p.size(), 0));
int n = (int) p.size();
vector<int> par(n, -1);
vector<bool> vis(n, false);
for (int i = 0; i < n; i++) {
vector<int> v;
if (!vis[i]) {
for (int j = 0; j < n; j++) {
if (p[i][j] == 2) {
v.push_back(j);
vis[i] = true; vis[j] = true;
}
}
if ((int) v.size() == 1) return 0;
if ((int) v.size() >= 2) {
for (int j = 0; j + 1 < (int) v.size(); j++) {
b[v[j]][v[j + 1]] = 1;
b[v[j + 1]][v[j]] = 1;
}
b[v[0]][i] = 1;
b[i][v[0]] = 1;
b[v[(int) v.size() - 1]][i] = 1;
b[i][v[(int) v.size() - 1]] = 1;
}
}
}
for (int i = 0; i < n; i++) par[i] = i;
for (int i = 0; i < n; i++) {
for (int j = 0; j < i; j++) {
if (p[i][j] == 2) par[j] = i;
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (par[i] == par[j] && p[i][j] == 0) return 0;
if (par[i] != par[j] && p[i][j] == 2) return 0;
}
}
build(b);
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... |