# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
300354 | Elegia | Connecting Supertrees (IOI20_supertrees) | C++17 | 272 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 <functional>
#include <vector>
#include <iostream>
using namespace std;
int construct(vector<vector<int>> p) {
int n = p.size();
for (int i = 0; i < n; ++i)
for (int j = 0; j < n; ++j)
if (p[i][j] == 3) return 0;
vector<vector<int>> answer(n, vector<int>(n));
vector<int> vis(n, -1);
int cur = 0, mask = 0;
function<void(int)> dfs = [&](int u) {
vis[u] = cur;
for (int v = 0; v < n; ++v)
if (vis[v] == -1 && ((mask >> p[u][v]) & 1))
dfs(v);
};
mask = 6;
for (int i = 0; i < n; ++i)
if (vis[i] == -1) {
cur = i;
dfs(i);
}
for (int i = 0; i < n; ++i)
for (int j = 0; j < n; ++j)
if (vis[i] == vis[j] && !p[i][j])
return 0;
mask = 2;
auto vis2 = vis;
vis.assign(n, -1);
for (int i = 0; i < n; ++i)
if (vis[i] == -1) {
cur = i;
dfs(i);
}
for (int i = 0; i < n; ++i)
for (int j = 0; j < n; ++j)
if (vis[i] == vis[j] && p[i][j] == 2)
return 0;
vector<int> cand(n, -1);
vector<vector<int>> cycs(n);
for (int i = 0; i < n; ++i) {
if (cand[vis[i]] == -1) {
cand[vis[i]] = i;
cycs[vis2[i]].push_back(i);
} else {
answer[cand[vis[i]]][i] = answer[i][cand[vis[i]]] = 1;
}
}
for (auto cyc : cycs) {
if (cyc.size() > 1) {
if (cyc.size() < 3) return 0;
answer[cyc[0]][cyc.back()] = answer[cyc.back()][cyc[0]] = 1;
for (int i = 1; i < cyc.size(); ++i)
answer[cyc[i - 1]][cyc[i]] = answer[cyc[i]][cyc[i - 1]] = 1;
}
}
build(answer);
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... |