# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
622383 | happypotato | Connecting Supertrees (IOI20_supertrees) | C++17 | 1193 ms | 1871404 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;
#define ll long long
#define pii pair<int, int>
#define ff first
#define ss second
#define pb push_back
//
const int mxN = 1001;
vector<vector<int>> paths;
int n;
bool st1() {
vector<vector<int>> ans;
ans.resize(n);
for (int i = 0; i < n; i++) ans[i].resize(n);
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
ans[i][j] = (abs(i - j) == 1);
}
}
build(ans);
return true;
}
bool vis[mxN];
void resetvis() {
for (int i = 0; i < n; i++) vis[i] = false;
}
vector<vector<int>> components;
vector<int> curcomponent;
void dfs(int u, int tar) {
curcomponent.pb(u);
vis[u] = true;
for (int v = 0; v < n; v++) {
if (u != v && 1 <= paths[u][v] && paths[u][v] <= tar) {
dfs(v, tar);
}
}
}
int rep[mxN];
int repcnt = 1;
bool fullsol() {
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (paths[i][j] == 3) return false;
}
}
for (int i = 0; i < n; i++) {
if (!vis[i]) {
dfs(i, 2);
components.pb(curcomponent);
curcomponent.clear();
}
}
vector<vector<int>> ans(n);
for (int i = 0; i < n; i++) ans[i].resize(n, 0);
vector<vector<int>> decomp;
for (vector<int> &cur : components) {
decomp.clear();
for (int &u : cur) {
for (int &v : cur) {
if (!vis[u] && paths[u][v] == 1) {
dfs(u, 1);
for (int &x : curcomponent) rep[x] = repcnt;
repcnt++;
decomp.pb(curcomponent);
curcomponent.clear();
break;
}
}
if (!vis[u]) decomp.pb({u});
}
for (int &u : cur) {
for (int &v : cur) {
if (paths[u][v] != 1 + (rep[u] != rep[v])) return false;
}
}
for (vector<int> &process : decomp) {
for (int i = 1; i < process.size(); i++) {
ans[process[i - 1]][process[i]] = 1;
}
}
if (decomp.size() >= 2) {
for (int i = 1; i < decomp.size(); i++) {
ans[decomp[i - 1][0]][decomp[i][0]] = 1;
}
ans[decomp.front()[0]][decomp.back()[0]] = 1;
}
}
build(ans);
return true;
}
int construct(vector<vector<int>> p) {
n = p.size(); paths = p;
int st = 0;
for (vector<int> &curv : p) {
for (int &cur : curv) {
st |= (1 << cur);
}
}
if (st == 2) return st1();
else return fullsol();
}
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... |