# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
303419 | mechfrog88 | Connecting Supertrees (IOI20_supertrees) | C++14 | 266 ms | 22264 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>
typedef long long ll;
using namespace std;
int construct(vector<vector<int>> p) {
int n = p.size();
vector<vector<int>> ans(n,vector<int>(n));
vector<bool> visited(n,false);
bool ok = true;
for (int z=0;z<n && ok;z++){
if (visited[z]) continue;
vector <ll> g1;
vector <ll> g2;
vector <ll> g3;
for (int x=0;x<n && ok;x++){
if (z == x) continue;
if (p[z][x] == 1){
g1.push_back(x);
visited[x] = true;
for (int x1=0;x1<n && ok;x1++){
if (p[z][x1] != p[x][x1]){
ok = false;
}
}
}
else if (p[z][x] == 2){
g2.push_back(x);
visited[x] = true;
for (int x1=0;x1<n && ok;x1++){
if (x1 == x) continue;
if (p[z][x1] == 0 && p[x][x1] != 0){
ok = false;
}
if (p[z][x1] != 0 && p[x][x1] != 2){
ok = false;
}
}
}
else if (p[z][x] == 3){
g3.push_back(x);
visited[x] = true;
for (int x1=0;x1<n && ok;x1++){
if (x1 == x) continue;
if (p[z][x1] == 0 && p[x][x1] != 0){
ok = false;
}
if (p[z][x1] != 0 && p[x][x1] != 3){
ok = false;
}
}
}
}
for (int x=0;x<g1.size();x++){
ans[z][g1[x]] = 1;
ans[g1[x]][z] = 1;
}
if (g2.size() < 2 && g2.size() > 0) ok = false;
else if (g2.size() > 0){
for (int x=0;x<g2.size()-1;x++){
ans[g2[x]][g2[x+1]] = 1;
}
ans[z][g2[0]] = 1;
ans[z][g2[g2.size()-1]] = 1;
}
if (g3.size() < 3 && g3.size() > 0) ok = false;
else if (g3.size() > 0){
for (int x=0;x<g3.size()-1;x++){
ans[g3[x]][g3[x+1]] = 1;
}
ans[z][g3[0]] = 1;
ans[z][g3[g3.size()-1]] = 1;
ans[g3[0]][g3[g3.size()-1]] = 1;
}
}
if (ok){
build(ans);
return 1;
} else {
return 0;
}
}
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... |