#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
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Answer gives possible 0 while actual possible 1 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Answer gives possible 0 while actual possible 1 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Incorrect |
0 ms |
348 KB |
Answer gives possible 0 while actual possible 1 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Answer gives possible 0 while actual possible 1 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Answer gives possible 0 while actual possible 1 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Answer gives possible 0 while actual possible 1 |
3 |
Halted |
0 ms |
0 KB |
- |