# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1108742 | SteveBro | Connecting Supertrees (IOI20_supertrees) | C++17 | 182 ms | 24144 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;
vector <vector<int>> sol;
int sef[1001];
int ef(int x)
{
if(sef[x]==x)
return x;
else
return sef[x]=ef(sef[x]);
}
vector <int> comp[1001],rez,l;
bool ok[1001];
int construct(vector <vector <int>> p)
{
int i,j,nr,n;
n=p.size();
for(i=0;i<n;i++)
sef[i]=i;
l.resize(n);
for(i=0;i<n;i++)
sol.push_back(l);
for(i=0;i<n;i++)
{
for(j=0,nr=0;j<n;j++)
{
if(p[i][j]==3)
return 0;
if(p[i][j]==0&&ef(i)==ef(j))
return 0;
if(p[i][j]>0)
sef[ef(i)]=ef(j);
if(p[i][j]==2)
nr++;
if(p[i][j]==1&&i!=j)
ok[i]=true;
}
if(nr==1)
return 0;
}
for(i=0;i<n;i++)
comp[ef(i)].push_back(i);
for(i=0;i<n;i++)
sef[i]=-1;
for(i=0;i<n;i++)
{
if(!comp[i].empty())
{
rez.clear();
for(auto x : comp[i])
{
if(!ok[x])/// se alfa pe ciclu
rez.push_back(x);
else
{
if(sef[x]==-1)///nou lant
{
rez.push_back(x);
sef[x]=x;
for(j=0;j<n;j++)
{
if(p[x][j]==1&&x!=j)
{
if(sef[j]==-1)
{
sef[j]=x;
sol[x][j]=sol[j][x]=1;
}
else
return 0;
}
}
}
else
{
for(j=0;j<n;j++)
{
if(p[x][j]==2&&sef[x]==sef[j])
return 0;
if(p[x][j]==1&&sef[x]!=sef[j])
return 0;
}
}
}
}
if(rez.size()>2)
{
for(j=1;j<rez.size();j++)
{
sol[rez[j-1]][rez[j]]=sol[rez[j]][rez[j-1]]=1;
}
sol[rez[0]][rez[j-1]]=sol[rez[j-1]][rez[0]]=1;
}
}
}
build(sol);
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... |