Submission #1053408

# Submission time Handle Problem Language Result Execution time Memory
1053408 2024-08-11T11:28:13 Z inesfi Connecting Supertrees (IOI20_supertrees) C++14
100 / 100
148 ms 34096 KB
#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 ()
            }
        }*/
        if (deux.size()==2){
            return 0;
        }
        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;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 4444 KB Output is correct
2 Correct 0 ms 4444 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 105 ms 34096 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 4444 KB Output is correct
2 Correct 0 ms 4444 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 105 ms 34096 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 0 ms 4444 KB Output is correct
11 Correct 0 ms 4444 KB Output is correct
12 Correct 6 ms 7516 KB Output is correct
13 Correct 109 ms 29780 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 60 ms 24104 KB Output is correct
18 Correct 1 ms 4696 KB Output is correct
19 Correct 0 ms 4444 KB Output is correct
20 Correct 26 ms 16292 KB Output is correct
21 Correct 103 ms 33968 KB Output is correct
22 Correct 104 ms 33872 KB Output is correct
23 Correct 128 ms 33876 KB Output is correct
24 Correct 120 ms 33872 KB Output is correct
25 Correct 47 ms 23888 KB Output is correct
26 Correct 44 ms 24144 KB Output is correct
27 Correct 109 ms 33828 KB Output is correct
28 Correct 111 ms 33836 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 0 ms 4444 KB Output is correct
3 Correct 0 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4532 KB Output is correct
6 Correct 0 ms 4444 KB Output is correct
7 Correct 0 ms 4444 KB Output is correct
8 Correct 5 ms 7508 KB Output is correct
9 Correct 106 ms 31572 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 5 ms 9564 KB Output is correct
13 Correct 126 ms 33688 KB Output is correct
14 Correct 0 ms 4440 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 3 ms 9164 KB Output is correct
17 Correct 55 ms 23704 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 0 ms 4444 KB Output is correct
20 Correct 0 ms 4444 KB Output is correct
21 Correct 27 ms 14556 KB Output is correct
22 Correct 148 ms 33684 KB Output is correct
23 Correct 105 ms 33624 KB Output is correct
24 Correct 111 ms 33616 KB Output is correct
25 Correct 42 ms 19792 KB Output is correct
26 Correct 46 ms 23696 KB Output is correct
27 Correct 103 ms 33668 KB Output is correct
28 Correct 110 ms 33816 KB Output is correct
29 Correct 42 ms 19736 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 0 ms 4444 KB Output is correct
3 Correct 1 ms 4440 KB Output is correct
4 Correct 28 ms 16192 KB Output is correct
5 Correct 106 ms 33868 KB Output is correct
6 Correct 102 ms 33828 KB Output is correct
7 Correct 116 ms 33876 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 27 ms 13916 KB Output is correct
10 Correct 103 ms 31824 KB Output is correct
11 Correct 102 ms 31828 KB Output is correct
12 Correct 110 ms 31824 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 0 ms 4444 KB Output is correct
15 Correct 0 ms 4444 KB Output is correct
16 Correct 32 ms 16132 KB Output is correct
17 Correct 105 ms 31764 KB Output is correct
18 Correct 104 ms 33836 KB Output is correct
19 Correct 104 ms 33836 KB Output is correct
20 Correct 111 ms 33876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 4444 KB Output is correct
2 Correct 0 ms 4444 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 105 ms 34096 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 0 ms 4444 KB Output is correct
11 Correct 0 ms 4444 KB Output is correct
12 Correct 6 ms 7516 KB Output is correct
13 Correct 109 ms 29780 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 60 ms 24104 KB Output is correct
18 Correct 1 ms 4696 KB Output is correct
19 Correct 0 ms 4444 KB Output is correct
20 Correct 26 ms 16292 KB Output is correct
21 Correct 103 ms 33968 KB Output is correct
22 Correct 104 ms 33872 KB Output is correct
23 Correct 128 ms 33876 KB Output is correct
24 Correct 120 ms 33872 KB Output is correct
25 Correct 47 ms 23888 KB Output is correct
26 Correct 44 ms 24144 KB Output is correct
27 Correct 109 ms 33828 KB Output is correct
28 Correct 111 ms 33836 KB Output is correct
29 Correct 1 ms 4444 KB Output is correct
30 Correct 0 ms 4444 KB Output is correct
31 Correct 0 ms 4444 KB Output is correct
32 Correct 1 ms 4444 KB Output is correct
33 Correct 1 ms 4532 KB Output is correct
34 Correct 0 ms 4444 KB Output is correct
35 Correct 0 ms 4444 KB Output is correct
36 Correct 5 ms 7508 KB Output is correct
37 Correct 106 ms 31572 KB Output is correct
38 Correct 1 ms 4444 KB Output is correct
39 Correct 1 ms 4444 KB Output is correct
40 Correct 5 ms 9564 KB Output is correct
41 Correct 126 ms 33688 KB Output is correct
42 Correct 0 ms 4440 KB Output is correct
43 Correct 1 ms 4444 KB Output is correct
44 Correct 3 ms 9164 KB Output is correct
45 Correct 55 ms 23704 KB Output is correct
46 Correct 1 ms 4444 KB Output is correct
47 Correct 0 ms 4444 KB Output is correct
48 Correct 0 ms 4444 KB Output is correct
49 Correct 27 ms 14556 KB Output is correct
50 Correct 148 ms 33684 KB Output is correct
51 Correct 105 ms 33624 KB Output is correct
52 Correct 111 ms 33616 KB Output is correct
53 Correct 42 ms 19792 KB Output is correct
54 Correct 46 ms 23696 KB Output is correct
55 Correct 103 ms 33668 KB Output is correct
56 Correct 110 ms 33816 KB Output is correct
57 Correct 42 ms 19736 KB Output is correct
58 Correct 1 ms 4444 KB Output is correct
59 Correct 0 ms 4444 KB Output is correct
60 Correct 3 ms 11356 KB Output is correct
61 Correct 58 ms 26004 KB Output is correct
62 Correct 1 ms 4488 KB Output is correct
63 Correct 0 ms 4444 KB Output is correct
64 Correct 0 ms 4444 KB Output is correct
65 Correct 26 ms 16524 KB Output is correct
66 Correct 47 ms 25944 KB Output is correct
67 Correct 47 ms 25880 KB Output is correct
68 Correct 46 ms 25936 KB Output is correct
69 Correct 42 ms 19796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 4444 KB Output is correct
2 Correct 0 ms 4444 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 105 ms 34096 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 0 ms 4444 KB Output is correct
11 Correct 0 ms 4444 KB Output is correct
12 Correct 6 ms 7516 KB Output is correct
13 Correct 109 ms 29780 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 60 ms 24104 KB Output is correct
18 Correct 1 ms 4696 KB Output is correct
19 Correct 0 ms 4444 KB Output is correct
20 Correct 26 ms 16292 KB Output is correct
21 Correct 103 ms 33968 KB Output is correct
22 Correct 104 ms 33872 KB Output is correct
23 Correct 128 ms 33876 KB Output is correct
24 Correct 120 ms 33872 KB Output is correct
25 Correct 47 ms 23888 KB Output is correct
26 Correct 44 ms 24144 KB Output is correct
27 Correct 109 ms 33828 KB Output is correct
28 Correct 111 ms 33836 KB Output is correct
29 Correct 1 ms 4444 KB Output is correct
30 Correct 0 ms 4444 KB Output is correct
31 Correct 0 ms 4444 KB Output is correct
32 Correct 1 ms 4444 KB Output is correct
33 Correct 1 ms 4532 KB Output is correct
34 Correct 0 ms 4444 KB Output is correct
35 Correct 0 ms 4444 KB Output is correct
36 Correct 5 ms 7508 KB Output is correct
37 Correct 106 ms 31572 KB Output is correct
38 Correct 1 ms 4444 KB Output is correct
39 Correct 1 ms 4444 KB Output is correct
40 Correct 5 ms 9564 KB Output is correct
41 Correct 126 ms 33688 KB Output is correct
42 Correct 0 ms 4440 KB Output is correct
43 Correct 1 ms 4444 KB Output is correct
44 Correct 3 ms 9164 KB Output is correct
45 Correct 55 ms 23704 KB Output is correct
46 Correct 1 ms 4444 KB Output is correct
47 Correct 0 ms 4444 KB Output is correct
48 Correct 0 ms 4444 KB Output is correct
49 Correct 27 ms 14556 KB Output is correct
50 Correct 148 ms 33684 KB Output is correct
51 Correct 105 ms 33624 KB Output is correct
52 Correct 111 ms 33616 KB Output is correct
53 Correct 42 ms 19792 KB Output is correct
54 Correct 46 ms 23696 KB Output is correct
55 Correct 103 ms 33668 KB Output is correct
56 Correct 110 ms 33816 KB Output is correct
57 Correct 42 ms 19736 KB Output is correct
58 Correct 1 ms 4444 KB Output is correct
59 Correct 0 ms 4444 KB Output is correct
60 Correct 1 ms 4440 KB Output is correct
61 Correct 28 ms 16192 KB Output is correct
62 Correct 106 ms 33868 KB Output is correct
63 Correct 102 ms 33828 KB Output is correct
64 Correct 116 ms 33876 KB Output is correct
65 Correct 1 ms 4444 KB Output is correct
66 Correct 27 ms 13916 KB Output is correct
67 Correct 103 ms 31824 KB Output is correct
68 Correct 102 ms 31828 KB Output is correct
69 Correct 110 ms 31824 KB Output is correct
70 Correct 1 ms 4444 KB Output is correct
71 Correct 0 ms 4444 KB Output is correct
72 Correct 0 ms 4444 KB Output is correct
73 Correct 32 ms 16132 KB Output is correct
74 Correct 105 ms 31764 KB Output is correct
75 Correct 104 ms 33836 KB Output is correct
76 Correct 104 ms 33836 KB Output is correct
77 Correct 111 ms 33876 KB Output is correct
78 Correct 1 ms 4444 KB Output is correct
79 Correct 0 ms 4444 KB Output is correct
80 Correct 3 ms 11356 KB Output is correct
81 Correct 58 ms 26004 KB Output is correct
82 Correct 1 ms 4488 KB Output is correct
83 Correct 0 ms 4444 KB Output is correct
84 Correct 0 ms 4444 KB Output is correct
85 Correct 26 ms 16524 KB Output is correct
86 Correct 47 ms 25944 KB Output is correct
87 Correct 47 ms 25880 KB Output is correct
88 Correct 46 ms 25936 KB Output is correct
89 Correct 42 ms 19796 KB Output is correct
90 Correct 1 ms 4440 KB Output is correct
91 Correct 0 ms 4444 KB Output is correct
92 Correct 2 ms 6748 KB Output is correct
93 Correct 44 ms 17812 KB Output is correct
94 Correct 1 ms 4444 KB Output is correct
95 Correct 0 ms 4444 KB Output is correct
96 Correct 1 ms 4444 KB Output is correct
97 Correct 11 ms 8980 KB Output is correct
98 Correct 45 ms 17748 KB Output is correct
99 Correct 49 ms 17748 KB Output is correct
100 Correct 44 ms 17744 KB Output is correct
101 Correct 41 ms 17592 KB Output is correct
102 Correct 43 ms 17748 KB Output is correct
103 Correct 41 ms 17748 KB Output is correct
104 Correct 51 ms 18000 KB Output is correct
105 Correct 51 ms 17748 KB Output is correct