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>
using namespace std;
vector<long>parent;
std::vector<std::vector<int> > answer;
long find_set(long x)
{
if(parent[x]==x){
return x;
}
long z=find_set(parent[x]);
parent[x]=z;
return z;
}
void union_set(long x,long z)
{
x=find_set(x);
z=find_set(z);
if(x!=z){
parent[z]=x;
}
}
int construct(std::vector<std::vector<int> > p) {
int n = p.size();
for(long i=0;i<n;i++){
parent.push_back(i);
}
for (int i = 0; i < n; i++) {
std::vector<int> row;
row.resize(n);
answer.push_back(row);
}
bool ok=true;
for(long i=0;i<n;i++){
for(long j=i+1;j<n;j++){
if(p[i][j]==2){
union_set(i,j);
}
}
}
for(long i=0;i<n;i++){
for(long j=i+1;j<n;j++){
if(p[i][j]==0){
if(find_set(i)==find_set(j)){
ok=false;
i=n;
break;
}
}
}
}
vector<vector<long> >v(n);
long x,z;
for(long i=0;i<n;i++){
x=find_set(i);
v[x].push_back(i);
}
for(long i=0;i<n;i++){
x=v[i].size();
if(x>1){
for(long j=0;j<x;j++){
z=v[i][(j+1)%x];
answer[v[i][z]][v[i][j]]=1;
answer[v[i][j]][v[i][z]]=1;
}
}
}
if(ok){
build(answer);
return 1;
}
return 0;
}
# | 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... |