# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
769103 | t6twotwo | Connecting Supertrees (IOI20_supertrees) | C++17 | 165 ms | 22076 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(std::vector<std::vector<int>> a) {
int N = a.size();
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
if (a[i][j] == 3) {
return 0;
}
}
}
vector<bool> vis(N);
auto bfs = [&](int s, int t) {
vector<int> v;
queue<int> q;
q.push(s);
vis[s] = 1;
while (!q.empty()) {
int x = q.front();
q.pop();
v.push_back(x);
for (int y = 0; y < N; y++) {
if (!vis[y] && a[x][y] == t) {
vis[y] = 1;
q.push(y);
}
}
}
return v;
};
vector ans(N, vector<int>(N));
for (int i = 0; i < N; i++) {
if (vis[i]) {
continue;
}
auto v = bfs(i, 1);
for (int x : v) {
for (int j = 0; j < N; j++) {
if (a[x][j] != a[v[0]][j]) {
return 0;
}
}
}
for (int j = 1; j < v.size(); j++) {
ans[i][v[j]] = ans[v[j]][i] = 1;
}
vis[i] = 0;
}
for (int i = 0; i < N; i++) {
if (vis[i]) {
continue;
}
auto v = bfs(i, 2);
if (v.size() == 1) {
continue;
}
if (v.size() == 2) {
return 0;
}
for (int j = 0; j < v.size(); j++) {
for (int k = j + 1; k < v.size(); k++) {
if (!a[v[j]][v[k]]) {
return 0;
}
}
}
for (int j = 0; j < v.size(); j++) {
int x = v[j];
int y = v[j + 1 == v.size() ? 0 : j + 1];
ans[x][y] = ans[y][x] = 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... |