#include "supertrees.h"
#include<bits/stdc++.h>
using namespace std;
using vv=vector<vector<int>>;
const int MAX_SOM=1005;
int nbSom;
vv adja,rep;
int pere[MAX_SOM][2];
vector<int> listeFils[MAX_SOM],listeBoucle[MAX_SOM];
int find(int pos,int tab) {
if (pere[pos][tab]!=pos) {
pere[pos][tab]=find(pere[pos][tab],tab);
}
return pere[pos][tab];
}
int construct(vv p) {
adja=p;
nbSom=adja.size();
for (int i=0;i<nbSom;i++) {
rep.push_back({});
for (int j=0;j<nbSom;j++) {
rep.back().push_back(0);
}
pere[i][0]=i;
pere[i][1]=i;
}
for (int i=0;i<nbSom;i++) {
for (int j=i+1;j<nbSom;j++) {
if (adja[i][j]==3) {
return 0;
}
if (adja[i][j]==1) {
if (find(i,0)!=find(j,0)) {
pere[find(i,0)][0]=find(j,0);
}
}
}
}
for (int i=0;i<nbSom;i++) {
//cout<<i<<" : "<<find(i,0)<<endl;
listeFils[find(i,0)].push_back(i);
}
for (int i=0;i<nbSom;i++) {
for (int j=1;j<(int)listeFils[i].size();j++) {
for (int k=0;k<nbSom;k++) {
if (adja[listeFils[i][j]]!=adja[listeFils[i][j-1]]) {
return 0;
}
}
rep[listeFils[i][j]][listeFils[i][j-1]]=1;
rep[listeFils[i][j-1]][listeFils[i][j]]=1;
}
}
for (int i=0;i<nbSom;i++) {
for (int j=i+1;j<nbSom;j++) {
if (!listeFils[i].empty() and !listeFils[j].empty() and find(i,1)!=find(j,1)) {
pere[find(i,1)][1]=find(j,1);
}
}
}
for (int i=0;i<nbSom;i++) {
if (!listeFils[i].empty()) {
listeBoucle[find(i,1)].push_back(i);
}
}
for (int i=0;i<nbSom;i++) {
if (listeBoucle[i].size()>1) {
for (int j=0;j<(int)listeBoucle[i].size();j++) {
rep[listeBoucle[i][j]][listeBoucle[i][(j+1)%listeBoucle[i].size()]]=1;
rep[listeBoucle[i][(j+1)%listeBoucle[i].size()]][listeBoucle[i][j]]=1;
}
}
}
build(rep);
return 1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
7 ms |
1364 KB |
Output is correct |
7 |
Correct |
217 ms |
26124 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
7 ms |
1364 KB |
Output is correct |
7 |
Correct |
217 ms |
26124 KB |
Output is correct |
8 |
Incorrect |
0 ms |
340 KB |
Too many ways to get from 0 to 1, should be 0 found no less than 1 |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
340 KB |
Too many ways to get from 0 to 1, should be 0 found no less than 1 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Too many ways to get from 0 to 1, should be 0 found no less than 1 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
7 ms |
1364 KB |
Output is correct |
7 |
Correct |
217 ms |
26124 KB |
Output is correct |
8 |
Incorrect |
0 ms |
340 KB |
Too many ways to get from 0 to 1, should be 0 found no less than 1 |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
7 ms |
1364 KB |
Output is correct |
7 |
Correct |
217 ms |
26124 KB |
Output is correct |
8 |
Incorrect |
0 ms |
340 KB |
Too many ways to get from 0 to 1, should be 0 found no less than 1 |
9 |
Halted |
0 ms |
0 KB |
- |