# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
880450 | AkibAzmain | Connecting Supertrees (IOI20_supertrees) | C++17 | 1 ms | 348 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>
using namespace std;
#include "supertrees.h"
#include <vector>
int construct(std::vector<std::vector<int>> p) {
int n = p.size();
std::vector<std::vector<int>> ans (n, vector < int > (n));
vector < pair < int, int > > dsu (n);
for (int i = 0; i < n; ++i) dsu[i].first = -1, dsu[i].second = 1;
for (int i = 0; i < n; ++i)
{
if (p[i][i] != 1) return 0;
for (int j = i + 1; j < n; ++j)
{
if (p[j][i] != p[i][j]) return 0;
if (p[i][j] == 2)
{
int ci = i, cj = j;
while (dsu[ci].first != -1) ci = dsu[ci].first;
while (dsu[cj].first != -1) cj = dsu[cj].first;
if (ci != cj)
{
if (dsu[ci].second < dsu[cj].second) swap (ci, cj);
dsu[cj].first = ci;
dsu[ci].second += dsu[cj].second;
}
}
}
}
for (int i = 0; i < n; ++i)
for (int j = i + 1; j < n; ++j)
if (p[i][j] == 0)
{
if (p[j][i] != p[i][j]) return 0;
int ci = i, cj = j;
while (dsu[ci].first != -1) ci = dsu[ci].first;
while (dsu[cj].first != -1) cj = dsu[cj].first;
if (ci == cj) return 0;
}
map < int, vector < int > > s;
for (int i = 0; i < n; ++i)
{
int ci = i;
while (dsu[ci].first != -1) ci = dsu[ci].first;
s[ci].push_back (i);
}
for (auto &[y, ss] : s)
{
for (int i = 1; i < ss.size (); ++i) ans[ss[i]][ss[i - 1]] = ans[ss[i - 1]][ss[i]] = 1;
if (ss.size () > 1) ans[ss.front ()][ss.back ()] = ans[ss.back ()][ss.front ()] = 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... |