# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
344696 | juggernaut | Connecting Supertrees (IOI20_supertrees) | C++14 | 288 ms | 28268 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>
#ifdef EVAL
#else
#include"grader.cpp"
#endif
using namespace std;
vector<vector<int>>P,res;
vector<int>comp;
int N,timer,pr[1005],id[1005];
bool vis[1005];
void dfs(int v){
comp.push_back(v);
pr[v]=v;
vis[v]=1;
id[v]=timer;
for(int i=0;i<N;i++)if(!vis[i]&&P[v][i]==1)vis[i]=1,pr[i]=v,id[i]=timer,res[v][i]=res[i][v]=1;
for(int i=0;i<N;i++)if(!vis[i]&&P[v][i]==2)dfs(i);
}
int construct(vector<vector<int>>p){
P=p;
N=p.size();
res.resize(N);
fill(res.begin(),res.end(),vector<int>(N,0));
// 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(!vis[i]){
timer++;
dfs(i);
if(comp.size()==2)return 0;
else if(comp.size()>2){
int j;
for(j=1;j<comp.size();j++)res[comp[j]][comp[j-1]]=res[comp[j-1]][comp[j]]=1;
res[comp[j-1]][comp[0]]=res[comp[0]][comp[j-1]]=1;
}
comp.clear();
}
for(int i=0;i<N;i++)for(int j=0;j<N;j++)
if(pr[i]==pr[j]&&p[i][j]!=1)return 0;
else if(id[i]==id[j]&&pr[i]!=pr[j]&&p[i][j]!=2)return 0;
else if(id[i]!=id[j]&&p[i][j])return 0;
build(res);
return 1;
}
/*
4
1 1 2 2
1 1 2 2
2 2 1 2
2 2 2 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... |