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;
const int N=1001;
int pa[N],pa1[N],pa2[N];
int dsu(int x){
if(pa[x]==x)return x;
else return pa[x]=dsu(pa[x]);
}
int dsu1(int x){
if(pa1[x]==x)return x;
else return pa1[x]=dsu1(pa1[x]);
}
int dsu2(int x){
if(pa2[x]==x)return x;
else return pa2[x]=dsu2(pa2[x]);
}
int construct(vector<vector<int>> p) {
int n=p.size();
vector<vector<int>> ans;
for (int i = 0; i < n; i++) {
vector<int> row;
row.resize(n);
ans.push_back(row);
pa[i]=i;
pa1[i]=i;
pa2[i]=i;
}
for(int i=0; i<n; i++){
for(int j=0; j<n; j++){
if(p[i][j]==3)return 0;
if(p[i][j]==1)pa1[dsu1(j)]=dsu1(i);
}
}
for(int i=0; i<n; i++){
for(int j=0; j<n; j++){
if(i!=j&&dsu1(i)==dsu1(j)&&dsu(i)!=dsu(j)){
ans[i][j]=ans[j][i]=1;
pa[dsu(i)]=dsu(j);
}
}
}
for(int i=0; i<n; i++){
for(int j=0; j<n; j++){
if(p[i][j]==2)pa2[dsu2(i)]=dsu2(j);
}
}
for(int i=0; i<n; i++){
for(int j=0; j<n; j++){
if((dsu1(i)==dsu1(j))!=(dsu2(i)==dsu2(j)))return 0;
}
}
build(ans);
return 1;
}
/*
6
1 2 2 0 0 0
2 1 2 0 0 0
2 2 1 0 0 0
0 0 0 1 2 2
0 0 0 2 1 2
0 0 0 2 2 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... |