# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
941237 | Numberz | Connecting Supertrees (IOI20_supertrees) | C++14 | 179 ms | 22356 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<std::vector<int>> p) {
//subtask 1
int n = p.size();
vector<vector<int>> res(n, vector<int>(n, 0));
//checker
vector<int> tracker(n, 0);
vector<vector<int>> components;
//checks if it is possible to build the bridges
for (int i = 0; i < n; i++) {
//checks if it should already be in a component
bool search = true;
for (int j = 0; j < components.size(); j++) {
if (p[components[j][0]][i] == 2) {
components[j].push_back(i);
//cout << "prob first " << i << ' ' << j <<endl;
//cout << "j: " << j << endl;
tracker[i] = j;
search = false;
break;
}
}
if (search) {
components.push_back({i});
//cout << "prob second " << i << ' ' << components.size()-1 <<endl;
//cout << "comps: " << components.size() << endl;
tracker[i] = components.size()-1;
}
}
//check if wrong
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (i != j) {
if ((tracker[i] == tracker[j] && p[i][j] == 0) || (tracker[i] != tracker[j] && p[i][j] != 0)) {
return 0;
}
}
}
}
//within each component, build a graph
// size shoud be > 1
for (auto comp : components) {
if (comp.size() > 1) {
if (comp.size() == 2) {
return 0;
}
int k = comp.size();
for (int i = 0; i < k-1; i++) {
res[comp[i]][comp[i+1]] = 1;
res[comp[i+1]][comp[i]] = 1;
}
res[comp[k-1]][comp[0]] = 1;
res[comp[0]][comp[k-1]] = 1;
}
}
build(res);
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... |