# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1043739 | DeathIsAwe | Connecting Supertrees (IOI20_supertrees) | C++14 | 125 ms | 22296 KiB |
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), forest;
vector<int> tree;
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);
}
}
for (int i=0;i<n;i++) {
if (visited[i]) {
continue;
}
visited[i] = true;
tree.clear(); tree.push_back(i);
for (int j=0;j<n;j++) {
if (j == i) {
continue;
}
if (p[i][j] == 1) {
if (visited[j]) {
return 0;
}
visited[j] = true;
tree.push_back(j);
} else if (p[i][j] == 3) {
return 0;
}
}
prev = i;
for (int j: tree) {
ans[prev][j] = 1;
ans[j][prev] = 1;
prev = j;
}
ans[i][i] = 0;
for (int j: tree) {
for (int k: tree) {
if (p[j][k] != 1) {
return 0;
}
}
}
forest.push_back(tree);
}
//for (vector<int> i: forest) {
// for (int j: i) {
// cout << j << ' ';
// }
// cout << '\n';
//}
for (int i=0;i<n;i++) {
visited[i] = false;
}
vector<int> group;
vector<int> grouptags(forest.size(), -1);
for (int i=0;i<forest.size();i++) {
if (visited[forest[i][0]]) {
continue;
}
visited[forest[i][0]] = true;
group = {i};
grouptags[i] = i;
for (int j=i+1;j<forest.size();j++) {
if (p[forest[i][0]][forest[j][0]] == 2) {
visited[forest[j][0]] = true;
group.push_back(j);
grouptags[j] = 0;
}
}
if (group.size() == 2) {
return 0;
}
for (int j: group) {
for (int k=0;k<forest.size();k++) {
if (j == k) {
continue;
}
if (grouptags[k] != i) {
for (int l: forest[k]) {
for (int m: forest[j]) {
if (p[m][l] != 0) {
return 0;
}
}
}
} else {
for (int l: forest[k]) {
for (int m: forest[j]) {
if (p[m][l] != 2) {
return 0;
}
}
}
}
}
}
prev = forest[i][0];
for (int j: group) {
ans[prev][forest[j][0]] = 1;
ans[forest[j][0]][prev] = 1;
prev = forest[j][0];
}
ans[forest[i][0]][forest[i][0]] = 0;
if (prev ==forest[i][0]) {
continue;
}
ans[prev][forest[i][0]] = 1;
ans[forest[i][0]][prev] = 1;
}
build(ans);
return 1;
}
Compilation message (stderr)
# | 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... |