# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
470427 | jazzup | Connecting Supertrees (IOI20_supertrees) | C++14 | 268 ms | 22268 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 <cstdio>
using namespace std;
int par[1010];
vector<int> heads[1000];
int findPar(int n){
if(par[n]==n)return n;
return par[n]=findPar(par[n]);
}
bool c[1010];
vector<vector<int> > answer;
int construct(vector<vector<int> > p) {
int n = p.size();
for(int i=0;i<=n;i++){
par[i]=i;
}
for(int i=0;i<n;i++){
vector<int> vv;
answer.push_back(vv);
for(int j=0;j<n;j++){
answer[i].push_back(0);
}
}
for(int i=0;i<n-1;i++){
for(int j=i+1;j<n;j++){
if(p[i][j]!=p[j][i])return 0;
}
}
for(int i=0;i<n-1;i++){
for(int j=i+1;j<n;j++){
if(p[i][j]==3)return 0;
if(p[i][j]==1){
if(findPar(i)<findPar(j)){
par[findPar(j)]=findPar(i);
answer[j][findPar(j)]=1;
answer[findPar(j)][j]=1;
}
else if(findPar(i)>findPar(j)){
par[findPar(i)]=findPar(j);
answer[i][findPar(i)]=1;
answer[findPar(i)][i]=1;
}
}
}
}
for(int i=0;i<n-1;i++){
for(int j=i+1;j<n;j++){
// if(i==j)continue;
if(p[i][j]==2){
c[findPar(i)]=true;
c[findPar(j)]=true;
if(findPar(i)<findPar(j)){
par[findPar(j)]=findPar(i);
}
else if(findPar(i)>findPar(j)){
par[findPar(i)]=findPar(j);
}
heads[findPar(i)].push_back(i);
heads[findPar(j)].push_back(j);
}
}
}
for(int h=0;h<n;h++){
if(!heads[h].empty()){
for(int i=0;i<heads[h].size()-1;i++){
answer[heads[h][i]][heads[h][i+1]]=1;
answer[heads[h][i+1]][heads[h][i]]=1;
}
answer[heads[h][heads[h].size()-1]][heads[h][0]]=1;
answer[heads[h][0]][heads[h][heads[h].size()-1]]=1;
}
if(heads[h].size()==2)return 0;
}
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
if(i==j)continue;
else if(p[i][j]==0){
if(findPar(i)==findPar(j)){
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... |