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 "supertrees.h"
#include <bits/stdc++.h>
using namespace std;
int construct(vector<vector<int>> p) {
int n = p.size(), prev;
vector<vector<int>> ans(n);
bool visited[n];
for (int i=0;i<n;i++) {
visited[i] = false;
for (int j=0;j<n;j++) {
ans[i].push_back(0);
}
}
vector<vector<int>> currentnodes(3);
for (int i=0;i<n;i++) {
if (visited[i]) {
continue;
}
visited[i] = true;
for (int j=0;j<3;j++) {
currentnodes[j].clear();
}
for (int j=0;j<n;j++) {
if (j == i) {
continue;
}
if (p[i][j] > 0) {
if (visited[j]) {
return 0;
}
visited[j] = true;
if (p[i][j] == 1) {
currentnodes[1].push_back(j);
} else if (p[i][j] == 2) {
currentnodes[2].push_back(j);
} else if (p[i][j] == 3) {
return 0;
}
}
}
//for (int j: currentnodes[1]) {
// cout << j << ' ';
//}
//cout << '\n';
//for (int j: currentnodes[2]) {
// cout << j << ' ';
//}
//cout << '\n';
for (int j: currentnodes[1]) {
for (int k=0;k<n;k++) {
if (!visited[k]) {
if (p[j][k] != 0) {
return 0;
}
}
}
}
for (int j: currentnodes[2]) {
for (int k=0;k<n;k++) {
if (!visited[k]) {
if (p[j][k] != 0) {
return 0;
}
}
}
}
if (currentnodes[2].size() == 1) {
return 0;
}
for (int j: currentnodes[1]) {
for (int k: currentnodes[1]) {
if (p[j][k] != 1) {
return 0;
}
}
for (int k: currentnodes[2]) {
if (p[j][k] != 2) {
return 0;
}
}
}
for (int j: currentnodes[2]) {
for (int k: currentnodes[2]) {
if (j == k) {
continue;
}
if (p[j][k] != 2) {
return 0;
}
}
}
prev = i;
for (int j: currentnodes[1]) {
ans[prev][j] = 1;
ans[j][prev] = 1;
prev = j;
}
prev = i;
for (int j: currentnodes[2]) {
ans[prev][j] = 1;
ans[j][prev] = 1;
prev = j;
}
if (prev == i) {
continue;
}
ans[prev][i] = 1;
ans[i][prev] = 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... |