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];
bool vis1[N];
int dsu(int x){
if(pa[x]==x)return x;
else return pa[x]=dsu(pa[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;
}
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)pa[dsu(j)]=dsu(i);
}
}
for(int i=0; i<n; i++){
for(int j=0; j<n; j++){
if(i!=j&&dsu(i)==dsu(j)&&!vis1[i]){
if(p[i][j]!=1)return 0;
ans[i][j]=ans[j][i]=1;
vis1[i]=vis1[j]=true;
}
}
}
for(int i=0; i<n; i++){
for(int j=0; j<n; j++){
if(p[i][j]==2&&dsu(i)!=dsu(j)){
ans[i][j]=ans[j][i]=1;
pa[dsu(i)]=dsu(j);
break;
}
}
}
for(int i=0; i<n; i++){
for(int j=0; j<n; j++){
if(dsu(i)==dsu(j)&&!p[i][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
12
1 2 2 2 2 1 1 1 1 2 2 2
2 1 2 2 2 2 2 2 2 1 1 2
2 2 1 2 2 2 2 2 2 2 2 2
2 2 2 1 2 2 2 2 2 2 2 2
2 2 2 2 1 2 2 2 2 2 2 2
1 2 2 2 2 1 1 1 1 2 2 2
1 2 2 2 2 1 1 1 1 2 2 2
1 2 2 2 2 1 1 1 1 2 2 2
1 2 2 2 2 1 1 1 1 2 2 2
2 1 2 2 2 2 2 2 2 1 1 2
2 1 2 2 2 2 2 2 2 1 1 2
2 2 2 2 2 2 2 2 2 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... |