# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1000328 | codefox | Connecting Supertrees (IOI20_supertrees) | C++14 | 156 ms | 24148 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"
using namespace std;
int construct(std::vector<std::vector<int>> p)
{
int n = p.size();
vector<int> rep(n);
iota(rep.begin(), rep.end(), 0);
vector<vector<int>> b(n, vector<int>(n));
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 (rep[i]!=i) continue;
for (int j = i+1; j < n; j++)
{
if (p[i][j]!=1) continue;
for (int k = 0; k < n; k++)
{
if (p[i][k]!=p[j][k]) return 0;
}
b[i][j] = 1;
b[j][i] = 1;
rep[j] = i;
}
}
vector<int> vis(n,0);
for (int i = 0; i < n; i++)
{
if (rep[i]!=i) continue;
if (vis[i]) continue;
vector<int> cyc;
cyc.push_back(i);
for (int j = i+1; j < n; j++)
{
if (p[i][j]!=2) continue;
if (rep[j]!=j) continue;
for (int k = 0; k < n; k++)
{
if (p[i][k]==1 && rep[k]==i && p[j][k]==2) continue;
if (p[i][k]==2 && p[j][k]==1 && rep[k]==j) continue;
if (p[i][k]==2 && p[j][k]==2) continue;
if (p[i][k]==0 && p[j][k]==0) continue;
return 0;
}
vis[j] = 1;
cyc.push_back(j);
}
if (cyc.size()==1) continue;
if (cyc.size()==2) return 0;
for (int j = 0; j < cyc.size()-1; j++)
{
b[cyc[j]][cyc[j+1]] = 1;
b[cyc[j+1]][cyc[j]] = 1;
}
b[i][cyc.back()] = 1;
b[cyc.back()][i] = 1;
}
build(b);
return 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... |