#include "supertrees.h"
#include <vector>
#include<map>
#include<algorithm>
using namespace std;
const int maxn=1010;
int dsu[maxn];
int dsu2[maxn];
int cale(int a,int *dsu){
return dsu[a]==a ? a:cale(dsu[a],dsu);
}
void join(int a,int b,int *dsu){
dsu[cale(a,dsu)]=cale(b,dsu);
}
int construct(vector<vector<int>> p) {
int n = p.size();
vector<vector<int>> answer;
for (int i = 0; i < n; i++) {
vector<int> row;
row.resize(n);
answer.push_back(row);
}
for(int i=0;i<n;i++) dsu[i]=i;
for(int i=0;i<n;i++) dsu2[i]=i;
for(int i=0;i<n;i++){
for(int j=0;j<i;j++){
if(p[i][j]==1) join(i,j,dsu);
if(p[i][j]==3) return 0;
}
}
for(int i=0;i<n;i++){
if(i!=cale(i,dsu)){
answer[i][cale(i,dsu)]=1;
answer[cale(i,dsu)][i]=1;
}
}
for(int i=0;i<n;i++){
for(int j=0;j<i;j++){
if(p[i][j]==0) if(cale(i,dsu)==cale(j,dsu)) return 0;
if(p[i][j]==2){
if(cale(i,dsu)==cale(j,dsu)) return 0;
join(cale(i,dsu),cale(j,dsu),dsu2);
}
}
}
for(int i=0;i<n;i++){
for(int j=0;j<i;j++){
if(p[i][j]==0) if(cale(cale(i,dsu),dsu2)==cale(cale(j,dsu),dsu2)) return 0;
}
}
map<int,vector<int> > kurac;
for(int i=0;i<n;i++){
kurac[cale(cale(i,dsu),dsu2)].push_back(cale(i,dsu));
}
for(auto i:kurac){
sort(i.second.begin(),i.second.end());
i.second.resize(unique(i.second.begin(),i.second.end())-i.second.begin());
int prev=i.second.back();
if(i.second.size()<3) return 0;
for(int j:i.second){
if(prev==j) break;
if(prev!=-1){
answer[prev][j]=1;
answer[j][prev]=1;
}
prev=j;
}
}
build(answer);
return 1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Answer gives possible 0 while actual possible 1 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Answer gives possible 0 while actual possible 1 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Answer gives possible 0 while actual possible 1 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Answer gives possible 0 while actual possible 1 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Answer gives possible 0 while actual possible 1 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Answer gives possible 0 while actual possible 1 |
2 |
Halted |
0 ms |
0 KB |
- |