# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
398507 | priority_queue | Connecting Supertrees (IOI20_supertrees) | C++14 | 1 ms | 204 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.
// ioi 2020, day 1, supertrees
#include <bits/stdc++.h>
using namespace std;
#define forint(i, N) for (int i = 0; i < (N); i++)
using namespace std;
void build(std::vector<std::vector<int> > b);
int construct(vector<std::vector<int> > p) {
int N = p.size();
vector< vector<int> > b(N, vector<int>(N, 0));
vector<int> visited(N, -1);
vector<std::vector<int> > p2(N, vector<int>(N, 0));
forint(i, N) {
if (visited[i] < 0) { // create new. All connected to i also not visited
visited[i] = i;
vector< vector<int> > circle(1);
vector<int> path2 = {};
for (int j = i+1; j < N; j++) {
if (p[i][j] == 1) {
if (visited[j] >=0) {
return 0;
}
b[i][j] = 1;
b[j][i] = 1;
visited[j] = i;
circle[0].push_back(j);
continue;
}
if (p[i][j] == 2) {
if (visited[j] >=0) {
return 0;
}
path2.push_back(j);
//visited[j] = i;
continue;
}
if (p[i][j] == 3) {
return 0;
}
}
if (!path2.empty()) {
if (path2.size() < 2) {
return 0;
}
int last = i;
forint(j, path2.size()) {
if (visited[path2[j]] < 0) {
// make it root
b[last][path2[j]] = 1;
b[path2[j]][last] = 1;
last = path2[j];
visited[path2[j]] = i;
circle.push_back({path2[j]});
for (int j2 = j+1; j2 < path2.size(); j2++) {
if (visited[path2[j2]] < 0 && p[path2[j]][path2[j2]] == 1) {
b[path2[j]][path2[j2]] = 1;
b[path2[j2]][path2[j]] = 1;
visited[path2[j2]] = path2[j];
circle[circle.size()-1].push_back(path2[j2]);
}
}
}
}
b[i][last] = 1;
b[last][i] = 1;
}
forint(c, circle.size()) {
for (int d1 = 0; d1 < circle[c].size(); d1++) {
for (int d2 = 0; d2 < circle[c].size(); d2++) {
p2[circle[c][d1]][circle[c][d2]] = 1;
}
}
forint(d, circle.size()) {
if (c!=d) {
for (int d1 = 0; d1 < circle[c].size(); d1++) {
for (int d2 = 0; d2 < circle[d].size(); d2++) {
p2[circle[c][d1]][circle[d][d2]] = 2;
}
}
}
}
}
}/*
else { // check if it is OK
if (p[visited[i]][i] == 1) {
for (int j = i+1; j < N; j++) {
if (p[visited[i]][j] != p[i][j]) {
return 0;
}
}
}
else {
for (int j = i+1; j < N; j++) {
if (visited[j] < 0) {
if (p[i][j] > 0) {
return 0;
}
}
else {
if (p[i][j]==3 || (p[i][j]==0 && p[visited[i]][j] != 0) || (p[i][j]==1 && p[visited[i]][j] != 2) || (p[i][j]==2 && p[visited[i]][j] != 2) ){
return 0;
}
}
}
}
for (int j = i+1; j < N; j++) {
if (p[i][j] == 3) {
return 0;
}
if (p[i][j] == 2) {
if (visited[i] != visited[j]) {
if (p[visited[i]][visited[j]] != 2) {
return 0;
}
}
else {
if (p[visited[i]][j] != 2) {
return 0;
}
}
}
if (p[i][j] == 1) {
if (visited[i] != visited[j]) {
return 0;
}
if (p[visited[i]][i] == 2 || p[visited[i]][j] == 2) {
return 0;
}
}
}
}*/
}
forint(i, N) {
forint(j, N) {
if (p2[i][j] != p[i][j]) {
return 0;
}
}
}
build(b);
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... |