Submission #810991

# Submission time Handle Problem Language Result Execution time Memory
810991 2023-08-06T19:10:02 Z oscar1f Connecting Supertrees (IOI20_supertrees) C++17
100 / 100
210 ms 28200 KB
#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 adja[i][j]==2 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) {
            if (listeBoucle[i].size()==2) {
                return 0;
            }
            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;
            }
        }
    }
    for (int i=0;i<nbSom;i++) {
        //cout<<i<<" : "<<find(i,0)<<" "<<find(find(i,0),1)<<endl;
        if (!listeFils[i].empty()) {
            for (int j=0;j<nbSom;j++) {
                if (i!=j) {
                    if (find(i,1)!=find(find(j,0),1)) {
                        if (adja[i][j]!=0) {
                            return 0;
                        } 
                    }
                    else if (find(i,0)!=find(j,0)) {
                        if (adja[i][j]!=2) {
                            return 0;
                        } 
                    }
                }
            }
        }
    }
	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 0 ms 340 KB Output is correct
6 Correct 7 ms 1364 KB Output is correct
7 Correct 209 ms 26184 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 0 ms 340 KB Output is correct
6 Correct 7 ms 1364 KB Output is correct
7 Correct 209 ms 26184 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 7 ms 1364 KB Output is correct
13 Correct 161 ms 26176 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 3 ms 980 KB Output is correct
17 Correct 71 ms 16196 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 43 ms 6816 KB Output is correct
21 Correct 200 ms 26048 KB Output is correct
22 Correct 196 ms 26120 KB Output is correct
23 Correct 210 ms 26068 KB Output is correct
24 Correct 167 ms 26172 KB Output is correct
25 Correct 97 ms 16192 KB Output is correct
26 Correct 79 ms 16184 KB Output is correct
27 Correct 206 ms 26052 KB Output is correct
28 Correct 163 ms 26220 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 7 ms 1484 KB Output is correct
9 Correct 161 ms 28052 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 7 ms 1496 KB Output is correct
13 Correct 170 ms 28084 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 4 ms 1108 KB Output is correct
17 Correct 81 ms 18252 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 41 ms 7292 KB Output is correct
22 Correct 164 ms 28088 KB Output is correct
23 Correct 165 ms 28200 KB Output is correct
24 Correct 175 ms 28108 KB Output is correct
25 Correct 64 ms 18212 KB Output is correct
26 Correct 68 ms 18196 KB Output is correct
27 Correct 162 ms 28072 KB Output is correct
28 Correct 176 ms 28084 KB Output is correct
29 Correct 66 ms 18216 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 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 43 ms 6792 KB Output is correct
5 Correct 200 ms 26164 KB Output is correct
6 Correct 191 ms 26140 KB Output is correct
7 Correct 206 ms 26168 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 41 ms 6796 KB Output is correct
10 Correct 163 ms 26168 KB Output is correct
11 Correct 162 ms 26188 KB Output is correct
12 Correct 175 ms 26164 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 41 ms 6840 KB Output is correct
17 Correct 163 ms 26152 KB Output is correct
18 Correct 183 ms 26176 KB Output is correct
19 Correct 180 ms 26112 KB Output is correct
20 Correct 168 ms 26316 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 0 ms 340 KB Output is correct
6 Correct 7 ms 1364 KB Output is correct
7 Correct 209 ms 26184 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 7 ms 1364 KB Output is correct
13 Correct 161 ms 26176 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 3 ms 980 KB Output is correct
17 Correct 71 ms 16196 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 43 ms 6816 KB Output is correct
21 Correct 200 ms 26048 KB Output is correct
22 Correct 196 ms 26120 KB Output is correct
23 Correct 210 ms 26068 KB Output is correct
24 Correct 167 ms 26172 KB Output is correct
25 Correct 97 ms 16192 KB Output is correct
26 Correct 79 ms 16184 KB Output is correct
27 Correct 206 ms 26052 KB Output is correct
28 Correct 163 ms 26220 KB Output is correct
29 Correct 0 ms 340 KB Output is correct
30 Correct 0 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 0 ms 340 KB Output is correct
33 Correct 0 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 0 ms 340 KB Output is correct
36 Correct 7 ms 1484 KB Output is correct
37 Correct 161 ms 28052 KB Output is correct
38 Correct 0 ms 340 KB Output is correct
39 Correct 0 ms 340 KB Output is correct
40 Correct 7 ms 1496 KB Output is correct
41 Correct 170 ms 28084 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 4 ms 1108 KB Output is correct
45 Correct 81 ms 18252 KB Output is correct
46 Correct 0 ms 340 KB Output is correct
47 Correct 0 ms 340 KB Output is correct
48 Correct 0 ms 340 KB Output is correct
49 Correct 41 ms 7292 KB Output is correct
50 Correct 164 ms 28088 KB Output is correct
51 Correct 165 ms 28200 KB Output is correct
52 Correct 175 ms 28108 KB Output is correct
53 Correct 64 ms 18212 KB Output is correct
54 Correct 68 ms 18196 KB Output is correct
55 Correct 162 ms 28072 KB Output is correct
56 Correct 176 ms 28084 KB Output is correct
57 Correct 66 ms 18216 KB Output is correct
58 Correct 1 ms 340 KB Output is correct
59 Correct 1 ms 340 KB Output is correct
60 Correct 3 ms 1108 KB Output is correct
61 Correct 68 ms 18216 KB Output is correct
62 Correct 0 ms 340 KB Output is correct
63 Correct 0 ms 356 KB Output is correct
64 Correct 0 ms 340 KB Output is correct
65 Correct 41 ms 7340 KB Output is correct
66 Correct 64 ms 18216 KB Output is correct
67 Correct 73 ms 18216 KB Output is correct
68 Correct 70 ms 18216 KB Output is correct
69 Correct 64 ms 18220 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 0 ms 340 KB Output is correct
6 Correct 7 ms 1364 KB Output is correct
7 Correct 209 ms 26184 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 7 ms 1364 KB Output is correct
13 Correct 161 ms 26176 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 3 ms 980 KB Output is correct
17 Correct 71 ms 16196 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 43 ms 6816 KB Output is correct
21 Correct 200 ms 26048 KB Output is correct
22 Correct 196 ms 26120 KB Output is correct
23 Correct 210 ms 26068 KB Output is correct
24 Correct 167 ms 26172 KB Output is correct
25 Correct 97 ms 16192 KB Output is correct
26 Correct 79 ms 16184 KB Output is correct
27 Correct 206 ms 26052 KB Output is correct
28 Correct 163 ms 26220 KB Output is correct
29 Correct 0 ms 340 KB Output is correct
30 Correct 0 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 0 ms 340 KB Output is correct
33 Correct 0 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 0 ms 340 KB Output is correct
36 Correct 7 ms 1484 KB Output is correct
37 Correct 161 ms 28052 KB Output is correct
38 Correct 0 ms 340 KB Output is correct
39 Correct 0 ms 340 KB Output is correct
40 Correct 7 ms 1496 KB Output is correct
41 Correct 170 ms 28084 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 4 ms 1108 KB Output is correct
45 Correct 81 ms 18252 KB Output is correct
46 Correct 0 ms 340 KB Output is correct
47 Correct 0 ms 340 KB Output is correct
48 Correct 0 ms 340 KB Output is correct
49 Correct 41 ms 7292 KB Output is correct
50 Correct 164 ms 28088 KB Output is correct
51 Correct 165 ms 28200 KB Output is correct
52 Correct 175 ms 28108 KB Output is correct
53 Correct 64 ms 18212 KB Output is correct
54 Correct 68 ms 18196 KB Output is correct
55 Correct 162 ms 28072 KB Output is correct
56 Correct 176 ms 28084 KB Output is correct
57 Correct 66 ms 18216 KB Output is correct
58 Correct 0 ms 340 KB Output is correct
59 Correct 0 ms 340 KB Output is correct
60 Correct 0 ms 340 KB Output is correct
61 Correct 43 ms 6792 KB Output is correct
62 Correct 200 ms 26164 KB Output is correct
63 Correct 191 ms 26140 KB Output is correct
64 Correct 206 ms 26168 KB Output is correct
65 Correct 0 ms 340 KB Output is correct
66 Correct 41 ms 6796 KB Output is correct
67 Correct 163 ms 26168 KB Output is correct
68 Correct 162 ms 26188 KB Output is correct
69 Correct 175 ms 26164 KB Output is correct
70 Correct 0 ms 340 KB Output is correct
71 Correct 1 ms 340 KB Output is correct
72 Correct 0 ms 340 KB Output is correct
73 Correct 41 ms 6840 KB Output is correct
74 Correct 163 ms 26152 KB Output is correct
75 Correct 183 ms 26176 KB Output is correct
76 Correct 180 ms 26112 KB Output is correct
77 Correct 168 ms 26316 KB Output is correct
78 Correct 1 ms 340 KB Output is correct
79 Correct 1 ms 340 KB Output is correct
80 Correct 3 ms 1108 KB Output is correct
81 Correct 68 ms 18216 KB Output is correct
82 Correct 0 ms 340 KB Output is correct
83 Correct 0 ms 356 KB Output is correct
84 Correct 0 ms 340 KB Output is correct
85 Correct 41 ms 7340 KB Output is correct
86 Correct 64 ms 18216 KB Output is correct
87 Correct 73 ms 18216 KB Output is correct
88 Correct 70 ms 18216 KB Output is correct
89 Correct 64 ms 18220 KB Output is correct
90 Correct 0 ms 340 KB Output is correct
91 Correct 0 ms 340 KB Output is correct
92 Correct 3 ms 1108 KB Output is correct
93 Correct 67 ms 18100 KB Output is correct
94 Correct 1 ms 340 KB Output is correct
95 Correct 0 ms 340 KB Output is correct
96 Correct 1 ms 340 KB Output is correct
97 Correct 16 ms 4780 KB Output is correct
98 Correct 64 ms 18100 KB Output is correct
99 Correct 65 ms 18124 KB Output is correct
100 Correct 63 ms 18092 KB Output is correct
101 Correct 62 ms 18088 KB Output is correct
102 Correct 62 ms 18140 KB Output is correct
103 Correct 67 ms 18216 KB Output is correct
104 Correct 62 ms 18100 KB Output is correct
105 Correct 67 ms 18100 KB Output is correct