| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 594243 | Pety | Connecting Supertrees (IOI20_supertrees) | C++14 | 227 ms | 28068 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 <bits/stdc++.h>
#include "supertrees.h"
#define ll long long
using namespace std;
const int INF = 1e9;
const int MOD = 1e9 + 7;
vector<vector<int>> p, ans;
vector<int>idk, comp;
int n, rep[1002], selected, viz[1002];
void dfs1 (int nod) {
rep[nod] = selected;
viz[nod] = 1;
for (int i = 0; i < n; i++)
if (p[nod][i] == 1 && !viz[i])
dfs1(i);
}
void dfs2 (int nod) {
comp.push_back(nod);
viz[nod] = 1;
for (auto it : idk)
if (!viz[it] && p[nod][it] == 2)
dfs2(it);
}
int construct (vector<vector<int>>aux) {
p = aux;
n = p.size();
ans.resize(n);
for (int i = 0; i < n; i++)
ans[i].resize(n);
for (int i = 0; i < n; i++)
if (!viz[i]) {
selected = i;
idk.push_back(selected);
dfs1(i);
}
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
if (rep[i] == rep[j] && p[i][j] != 1)
return 0;
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
if (rep[i] != rep[j] && p[i][j] != p[rep[i]][rep[j]])
return 0;
for (auto it : idk) {
int aux = -1;
for (int j = 0; j < n; j++)
if (rep[j] == it) {
if (aux != -1)
ans[aux][j] = ans[j][aux] = 1;
aux = j;
}
}
memset(viz, 0, sizeof(viz));
for (auto it : idk) {
if (!viz[it]) {
comp.clear();
dfs2(it);
if (comp.size() == 1)
continue;
if (comp.size() == 2)
return 0;
for (int i = 0; i < comp.size(); i++)
ans[comp[i]][comp[(i + 1) % comp.size()]] = ans[comp[(i + 1) % comp.size()]][comp[i]] = 1;
}
}
build(ans);
return 1;
}
// int main ()
// {
// cout << construct({{1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1}});
// 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... | ||||
