# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
432321 | arayi | Connecting Supertrees (IOI20_supertrees) | C++17 | 283 ms | 23996 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>
#define ad push_back
using namespace std;
const int N = 1111;
int col[N], sm[N], i1 = 1;
vector <vector <int> > b;
int n;
int construct(std::vector<std::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;
for (int i = 0; i < n; i++)
{
if(sm[i])
{
for (int j = 0; j < n; j++)
{
if(p[i][j] && sm[i] != sm[j]) return 0;
if(p[i][j] == 0 && sm[i] == sm[j]) return 0;
}
}
else
{
for (int j = 0; j < n; j++)
if(p[i][j]) sm[j] = i1;
}
i1++;
}
b.resize(n);
for (int i = 0; i < n; i++) b[i].resize(n);
for (int i = 1; i < i1; i++)
{
vector<int> fp;
for (int j = 0; j < n; j++)
if(sm[j] == i) fp.ad(j);
int nx = -1;
for (int j = 0; j < fp.size(); j++)
{
if(col[fp[j]]) continue;
if(nx != -1) b[nx][fp[j]] = b[fp[j]][nx] = 1;
nx = fp[j];
col[fp[j]] = 1;
for (int k = j + 1; k < fp.size(); k++)
if(p[fp[j]][fp[k]] == 1) b[fp[j]][fp[k]] = b[fp[k]][fp[j]] = 1, col[fp[k]] = 1;
}
if(nx != -1 && nx != fp[0]) b[nx][fp[0]] = b[fp[0]][nx] = 1;
}
build(b);
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... |