# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
603544 | Mher | Connecting Supertrees (IOI20_supertrees) | C++14 | 198 ms | 26072 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"
#include <vector>
using namespace std;
int n;
vector<vector<int>> a;
vector<int> col;
vector<vector<int>> r;
vector<int> gr;
vector<vector<int>> c;
vector<vector<int>> ans;
bool check()
{
for (int i = 0; i < r.size(); i++)
{
for (int j = 0; j < r[i].size(); j++)
{
for (int k = 0; k < j; k++)
{
if (a[r[i][j]][r[i][k]] != 1)
return false;
}
}
}
return true;
}
void conect(int v, int u)
{
ans[v][u] = 1;
ans[u][v] = 1;
}
void dfs(int v)
{
for (int i = 0; i < n; i++)
{
if (i == v)
continue;
if (a[v][i] == 1 && col[i] == -1)
{
r[col[v]].push_back(i);
col[i] = col[v];
dfs(i);
}
}
}
int construct(vector<vector<int>> p) {
n = p.size();
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
if (p[i][j] == 3)
return 0;
}
}
a = p;
ans = vector<vector<int>>(n, vector<int>(n, 0));
int cnt = 0;
col = vector<int>(n, -1);
for (int i = 0; i < n; i++)
{
if (col[i] == -1)
{
r.push_back(vector<int>(1, i));
col[i] = cnt++;
dfs(i);
}
}
if (!check())
return 0;
for (int i = 0; i < r.size(); i++)
{
for (int j = 0; j < r[i].size() - 1; j++)
{
conect(r[i][j], r[i][j + 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... |