#include "supertrees.h"
#include<bits/stdc++.h>
using namespace std;
const int TAILLEMAXI=1002;
int nbpers,couleur,u;
int dejavu[TAILLEMAXI];
int num[TAILLEMAXI];
int nbchem[TAILLEMAXI][TAILLEMAXI];
int vrai[TAILLEMAXI];
vector<int> ec;
vector<int> compo[TAILLEMAXI];
vector<int> un[TAILLEMAXI];
int val[TAILLEMAXI];
int rep[TAILLEMAXI][TAILLEMAXI];
vector<vector<int>> r;
vector<int> deux;
int pos[TAILLEMAXI][TAILLEMAXI];
void dfs1(int n){
if (dejavu[n]==1){
return ;
}
dejavu[n]=1;
num[n]=couleur;
ec.push_back(n);
for (int i=0;i<nbpers;i++){
if (nbchem[n][i]>0){
dfs1(i);
}
}
}
void dfs2(int n){
if (dejavu[n]==1){
return ;
}
dejavu[n]=1;
vrai[n]=1;
ec.push_back(n);
for (int i=0;i<nbpers;i++){
if (nbchem[n][i]==1){
dfs2(i);
}
}
}
bool verif3(){
bool pb=false;
for (int i=0;i<nbpers;i++){
for (int j=0;j<nbpers;j++){
if (nbchem[i][j]==3){
pb=true;
}
}
}
return pb;
}
int construct(vector<vector<int>> c) {
nbpers=c.size();
for (int i=0;i<nbpers;i++){
for (int j=0;j<nbpers;j++){
nbchem[i][j]=c[i][j];
}
}
if (verif3()==true){
return 0;
}
for (int i=0;i<nbpers;i++){
if (dejavu[i]==0){
ec.clear();
dfs1(i);
compo[couleur]=ec;
couleur++;
}
}
for (int j=0;j<nbpers;j++){
dejavu[j]=0;
}
for (int i=0;i<couleur;i++){
deux.clear();
for (int ipers=0;ipers<(int)compo[i].size();ipers++){
if (dejavu[compo[i][ipers]]==0){
deux.push_back(compo[i][ipers]);
}
ec.clear();
dfs2(compo[i][ipers]);
un[compo[i][ipers]]=ec;
if (ec.size()>1) {
for (int ilien=0;ilien<(int)un[compo[i][ipers]].size()-1;ilien++){
rep[un[compo[i][ipers]][ilien]][un[compo[i][ipers]][ilien+1]]=1;
rep[un[compo[i][ipers]][ilien+1]][un[compo[i][ipers]][ilien]]=1;
}
}
}
/*for (int ideux=0;ideux<(int)deux.size();ideux++){
for (int iautre=0;iautre<nbpers;iautre++){
if ()
}
}*/
for (int ideux=0;ideux<(int)deux.size()-1;ideux++){
rep[deux[ideux]][deux[ideux+1]]=1;
rep[deux[ideux+1]][deux[ideux]]=1;
}
if (deux.size()>2){
rep[deux[0]][deux[deux.size()-1]]=1;
rep[deux[deux.size()-1]][deux[0]]=1;
}
}
for (int i=0;i<nbpers;i++){
ec.clear();
for (int j=0;j<nbpers;j++){
if (rep[i][j]==1){
ec.push_back(1);
}
else {
ec.push_back(0);
}
}
r.push_back(ec);
}
for (int ipers=0;ipers<nbpers;ipers++){
if (un[ipers].size()>1){
for (int i=0;i<(int)un[ipers].size();i++){
for (int j=0;j<(int)un[ipers].size();j++){
pos[un[ipers][i]][un[ipers][j]]=1;
}
}
}
}
for (int i=0;i<nbpers;i++){
for (int j=0;j<nbpers;j++){
if (i!=j){
if (nbchem[i][j]==0 and num[i]==num[j]){
//cout<<i<<" "<<j<<endl;
//cout<<"un"<<endl;
return 0;
}
if (nbchem[i][j]==1 and pos[i][j]==0){
//cout<<i<<" "<<j<<endl;
return 0;
}
if (nbchem[i][j]==2 and pos[i][j]==1){
return 0;
}
}
}
}
build(r);
return 1;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4440 KB |
Output is correct |
3 |
Correct |
0 ms |
4444 KB |
Output is correct |
4 |
Correct |
0 ms |
4444 KB |
Output is correct |
5 |
Correct |
0 ms |
4444 KB |
Output is correct |
6 |
Correct |
5 ms |
11612 KB |
Output is correct |
7 |
Correct |
104 ms |
35924 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4440 KB |
Output is correct |
3 |
Correct |
0 ms |
4444 KB |
Output is correct |
4 |
Correct |
0 ms |
4444 KB |
Output is correct |
5 |
Correct |
0 ms |
4444 KB |
Output is correct |
6 |
Correct |
5 ms |
11612 KB |
Output is correct |
7 |
Correct |
104 ms |
35924 KB |
Output is correct |
8 |
Correct |
1 ms |
4440 KB |
Output is correct |
9 |
Correct |
1 ms |
4440 KB |
Output is correct |
10 |
Correct |
0 ms |
4444 KB |
Output is correct |
11 |
Correct |
0 ms |
4444 KB |
Output is correct |
12 |
Correct |
5 ms |
7516 KB |
Output is correct |
13 |
Correct |
98 ms |
31588 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
0 ms |
4444 KB |
Output is correct |
16 |
Correct |
4 ms |
11356 KB |
Output is correct |
17 |
Correct |
61 ms |
26008 KB |
Output is correct |
18 |
Correct |
1 ms |
4444 KB |
Output is correct |
19 |
Correct |
0 ms |
4444 KB |
Output is correct |
20 |
Correct |
25 ms |
16668 KB |
Output is correct |
21 |
Correct |
101 ms |
35924 KB |
Output is correct |
22 |
Correct |
98 ms |
35920 KB |
Output is correct |
23 |
Correct |
112 ms |
35992 KB |
Output is correct |
24 |
Correct |
98 ms |
35860 KB |
Output is correct |
25 |
Correct |
48 ms |
25880 KB |
Output is correct |
26 |
Correct |
46 ms |
25876 KB |
Output is correct |
27 |
Correct |
107 ms |
35920 KB |
Output is correct |
28 |
Correct |
98 ms |
35664 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
4444 KB |
Output is correct |
2 |
Correct |
0 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Incorrect |
0 ms |
4444 KB |
Answer gives possible 1 while actual possible 0 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4440 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
25 ms |
16664 KB |
Output is correct |
5 |
Correct |
103 ms |
35864 KB |
Output is correct |
6 |
Correct |
97 ms |
35924 KB |
Output is correct |
7 |
Correct |
124 ms |
35928 KB |
Output is correct |
8 |
Correct |
1 ms |
4440 KB |
Output is correct |
9 |
Correct |
26 ms |
14476 KB |
Output is correct |
10 |
Correct |
100 ms |
33620 KB |
Output is correct |
11 |
Correct |
100 ms |
33680 KB |
Output is correct |
12 |
Correct |
117 ms |
33620 KB |
Output is correct |
13 |
Correct |
1 ms |
4440 KB |
Output is correct |
14 |
Correct |
1 ms |
4440 KB |
Output is correct |
15 |
Correct |
0 ms |
4444 KB |
Output is correct |
16 |
Correct |
26 ms |
16720 KB |
Output is correct |
17 |
Correct |
101 ms |
33704 KB |
Output is correct |
18 |
Correct |
104 ms |
35864 KB |
Output is correct |
19 |
Correct |
102 ms |
35924 KB |
Output is correct |
20 |
Correct |
99 ms |
35760 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4440 KB |
Output is correct |
3 |
Correct |
0 ms |
4444 KB |
Output is correct |
4 |
Correct |
0 ms |
4444 KB |
Output is correct |
5 |
Correct |
0 ms |
4444 KB |
Output is correct |
6 |
Correct |
5 ms |
11612 KB |
Output is correct |
7 |
Correct |
104 ms |
35924 KB |
Output is correct |
8 |
Correct |
1 ms |
4440 KB |
Output is correct |
9 |
Correct |
1 ms |
4440 KB |
Output is correct |
10 |
Correct |
0 ms |
4444 KB |
Output is correct |
11 |
Correct |
0 ms |
4444 KB |
Output is correct |
12 |
Correct |
5 ms |
7516 KB |
Output is correct |
13 |
Correct |
98 ms |
31588 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
0 ms |
4444 KB |
Output is correct |
16 |
Correct |
4 ms |
11356 KB |
Output is correct |
17 |
Correct |
61 ms |
26008 KB |
Output is correct |
18 |
Correct |
1 ms |
4444 KB |
Output is correct |
19 |
Correct |
0 ms |
4444 KB |
Output is correct |
20 |
Correct |
25 ms |
16668 KB |
Output is correct |
21 |
Correct |
101 ms |
35924 KB |
Output is correct |
22 |
Correct |
98 ms |
35920 KB |
Output is correct |
23 |
Correct |
112 ms |
35992 KB |
Output is correct |
24 |
Correct |
98 ms |
35860 KB |
Output is correct |
25 |
Correct |
48 ms |
25880 KB |
Output is correct |
26 |
Correct |
46 ms |
25876 KB |
Output is correct |
27 |
Correct |
107 ms |
35920 KB |
Output is correct |
28 |
Correct |
98 ms |
35664 KB |
Output is correct |
29 |
Correct |
0 ms |
4444 KB |
Output is correct |
30 |
Correct |
0 ms |
4444 KB |
Output is correct |
31 |
Correct |
1 ms |
4444 KB |
Output is correct |
32 |
Incorrect |
0 ms |
4444 KB |
Answer gives possible 1 while actual possible 0 |
33 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4440 KB |
Output is correct |
3 |
Correct |
0 ms |
4444 KB |
Output is correct |
4 |
Correct |
0 ms |
4444 KB |
Output is correct |
5 |
Correct |
0 ms |
4444 KB |
Output is correct |
6 |
Correct |
5 ms |
11612 KB |
Output is correct |
7 |
Correct |
104 ms |
35924 KB |
Output is correct |
8 |
Correct |
1 ms |
4440 KB |
Output is correct |
9 |
Correct |
1 ms |
4440 KB |
Output is correct |
10 |
Correct |
0 ms |
4444 KB |
Output is correct |
11 |
Correct |
0 ms |
4444 KB |
Output is correct |
12 |
Correct |
5 ms |
7516 KB |
Output is correct |
13 |
Correct |
98 ms |
31588 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
0 ms |
4444 KB |
Output is correct |
16 |
Correct |
4 ms |
11356 KB |
Output is correct |
17 |
Correct |
61 ms |
26008 KB |
Output is correct |
18 |
Correct |
1 ms |
4444 KB |
Output is correct |
19 |
Correct |
0 ms |
4444 KB |
Output is correct |
20 |
Correct |
25 ms |
16668 KB |
Output is correct |
21 |
Correct |
101 ms |
35924 KB |
Output is correct |
22 |
Correct |
98 ms |
35920 KB |
Output is correct |
23 |
Correct |
112 ms |
35992 KB |
Output is correct |
24 |
Correct |
98 ms |
35860 KB |
Output is correct |
25 |
Correct |
48 ms |
25880 KB |
Output is correct |
26 |
Correct |
46 ms |
25876 KB |
Output is correct |
27 |
Correct |
107 ms |
35920 KB |
Output is correct |
28 |
Correct |
98 ms |
35664 KB |
Output is correct |
29 |
Correct |
0 ms |
4444 KB |
Output is correct |
30 |
Correct |
0 ms |
4444 KB |
Output is correct |
31 |
Correct |
1 ms |
4444 KB |
Output is correct |
32 |
Incorrect |
0 ms |
4444 KB |
Answer gives possible 1 while actual possible 0 |
33 |
Halted |
0 ms |
0 KB |
- |