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<bits/stdc++.h>
using namespace std;
int sz;
vector<vector<int> >v;
vector<vector<int> >ans;
int pr[1005];
int fp(int a){
if(pr[a]==a){
return a;
}
return pr[a]=fp(pr[a]);
}
void un(int a,int b){
if(fp(a)!=fp(b)){
ans[a][b]=1;
ans[b][a]=1;
pr[fp(b)]=fp(a);
}
}
void build_1(){
for(int i=0;i<sz;i++){
for(int j=i+1;j<sz;j++){
if(v[i][j]==1){
un(i,j);
}
}
}
}
bool check_0(){
for(int i=0;i<sz;i++){
for(int j=i+1;j<sz;j++){
if(v[i][j]==0&&fp(i)==fp(j))return 0;
}
}
return 1;
}
int construct(vector<vector<int> > p) {
//cout<<"work"<<endl;
sz = p.size();
bool check=0;
v.resize(sz);
for(int i=0;i<sz;i++){
v[i].resize(sz);
}
for(int i=0;i<sz;i++){
for(int j=0;j<sz;j++){
//cout<<"i j "<<i<<" "<<j<<endl;
v[i][j]=p[i][j];
if(p[i][j]!=p[j][i]||(i==j&&p[i][j]!=1)){
check=1;
//cout<<"break"<<endl;
break;
}
}
}
//cout<<"work"<<endl;
if(check){
return 0;
}
//cout<<"work"<<endl;
ans.resize(sz);
for(int i=0;i<sz;i++){
ans[i].resize(sz);
}
for(int i=0;i<sz;i++){
pr[i]=i;
}
//cout<<"work"<<endl;
build_1();
if(!check_0()){
return 0;
}else{
build(ans);
}
//cout<<"ans:"<<endl;
return 1;
}
# | 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... |