# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
470282 | jazzup | Connecting Supertrees (IOI20_supertrees) | C++14 | 1 ms | 332 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>
using namespace std;
int par[1010];
vector<int> heads;
int findPar(int n){
if(par[n]==n)return n;
return par[n]=findPar(par[n]);
}
bool c[1010];
int construct(vector<vector<int> > p) {
int n = p.size();
vector<vector<int> > answer;
for (int i = 0; i < n; i++) {
vector<int> row;
row.resize(n);
answer.push_back(row);
}
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
answer[i][j]=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){
par[j]=findPar(i);
answer[j][par[j]]=1;
answer[par[j]][j]=1;
}
}
}
for(int i=0;i<n-1;i++){
for(int j=i+1;j<n;j++){
if(p[i][j]==2){
if(findPar(i)==findPar(j)){
return 0;
}
c[findPar(i)]=true;
c[findPar(j)]=true;
}
}
}
for(int i=0;i<n;i++){
if(c[i])heads.push_back(i);
}
for(int i=0;i<heads.size()-1;i++){
answer[heads[i]][heads[i+1]]=1;
answer[heads[i+1]][heads[i]]=1;
}
answer[heads[heads.size()-1]][heads[0]]=1;
answer[heads[0]][heads[heads.size()-1]]=1;
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... |