# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
730124 | lucri | Connecting Supertrees (IOI20_supertrees) | C++17 | 199 ms | 22132 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 <vector>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <string>
int t[1010];
bool e[1010],dc[1010],ca[1010];
int tata(int nod)
{
if(t[nod]==nod) return nod;
return t[nod]=tata(t[nod]);
}
int construct(std::vector<std::vector<int>> p) {
int n = p.size();
std::vector<std::vector<int>> answer;
answer.resize(n);
for (int i = 0; i < n; i++) {
t[i]=i;
dc[i]=false;
e[i]=true;
answer[i].resize(n);
}
for(int i=0;i<n;++i)
{
if(p[i][i]!=1)
return 0;
for(int j=0;j<n;++j)
if(p[i][j]==1)
{
if(tata(i)!=tata(j))
{
answer[i][j]=answer[j][i]=1;
t[t[i]]=t[j];
}
}
}
for(int i=0;i<n;++i)
{
for(int j=0;j<n;++j)
if(p[i][j]==0)
{
if(tata(i)==tata(j))
return 0;
}
}
for(int i=0;i<n;++i)
if(e[i])
for(int j=i+1;j<n;++j)
{
if(e[j])
if(tata(i)==tata(j))
{
e[j]=false;
for(int q=0;q<n;++q)
if(p[i][q]!=p[j][q])
return 0;
}
}
int ciclu[1010];
for(int i=0;i<n;++i)
{
for(int q=0;q<n;++q)
ca[q]=false;
ca[i]=true;
if(e[i]==true&&dc[i]==false)
{
ciclu[0]=1;
ciclu[1]=i;
for(int j=0;j<n;++j)
if(e[j]&&p[i][j]==2)
{
ciclu[++ciclu[0]]=j;
ca[j]=true;
}
if(ciclu[0]>2)
{
for(int ii=1;ii<ciclu[0];++ii)
{
dc[ciclu[ii]]=true;
answer[ciclu[ii]][ciclu[ii+1]]=answer[ciclu[ii+1]][ciclu[ii]]=1;
for(int q=0;q<n;++q)
{
if(q!=ciclu[ii])
if(ca[q]==false&&p[ciclu[i]][q]==2||ca[q]==true&&p[ciclu[i]][q]!=2)
return 0;
}
}
answer[ciclu[ciclu[0]]][ciclu[1]]=answer[ciclu[1]][ciclu[ciclu[0]]]=1;
}
else if(ciclu[0]==2)
return 0;
}
}
build(answer);
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... |