Submission #613925

# Submission time Handle Problem Language Result Execution time Memory
613925 2022-07-30T13:22:58 Z Mounir Connecting Supertrees (IOI20_supertrees) C++14
100 / 100
245 ms 22388 KB
#include "supertrees.h"
#include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define chmax(x, v) x = max(x, v)
#define chmin(x, v) x = min(x, v)
#define pb push_back
#define pii pair<int, int>
#define sz(x) (int)x.size()
#define x first
#define y second
using namespace std;
 
const int N = 2000;
bool vu[N];
bool fini[N];
int composante[N], iArbre[N];
 
int construct(vector<vector<int>> nChemins) {
	int nNoeuds = sz(nChemins), nCCs = 0;
	vector<vector<int>> aretes(nNoeuds);
	for (vector<int>& ligne : aretes){
		ligne.resize(nNoeuds);
		for (int& val : ligne)
			val = 0;
	}
	for (int root = 0; root < nNoeuds; ++root){
		if (vu[root]) continue;
		vector<int> cc;
		for (int noeud = 0; noeud < nNoeuds; ++noeud){
			if (root == noeud || nChemins[noeud][root] > 0){
				cc.pb(noeud);
				composante[noeud] = nCCs;
			}
		}
 
		vector<int> darons;
		int nArbres = 0;
		for (int noeud : cc){
			if (fini[noeud]) continue;
			darons.pb(noeud);
			for (int autreNoeud : cc){
				if (!fini[autreNoeud] && nChemins[autreNoeud][noeud] == 1){
					fini[autreNoeud] = true;
					iArbre[autreNoeud] = nArbres;
					if (autreNoeud != noeud)
						aretes[noeud][autreNoeud] = aretes[autreNoeud][noeud] = 1;
				}
			}
			nArbres++;
		}
 
		if (sz(darons) > 1){
			for (int i = 0; i < sz(darons); ++i){
				int a = darons[i], b = darons[(i + 1)%sz(darons)];
				aretes[a][b] = aretes[b][a] = 1;
			}
		}
 
		if (sz(darons) == 2)
			return 0;
 
		nCCs++;
	}
 
	//verifier que c'est bon
	bool ok = true;
	for (int noeud = 0; noeud < nNoeuds; ++noeud)
		for (int voisin = 0; voisin < nNoeuds; ++voisin){
			if (composante[noeud] != composante[voisin])
				ok &= (nChemins[noeud][voisin] == 0);
			else if (iArbre[noeud] == iArbre[voisin])
				ok &= (nChemins[noeud][voisin] == 1);
			else 
				ok &= (nChemins[noeud][voisin] == 2);
		}
 
	if (!ok)
		return 0;
 
	build(aretes);
	return 1;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 300 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 308 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 9 ms 1236 KB Output is correct
7 Correct 176 ms 22264 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 300 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 308 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 9 ms 1236 KB Output is correct
7 Correct 176 ms 22264 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 12 ms 1184 KB Output is correct
13 Correct 237 ms 22312 KB Output is correct
14 Correct 1 ms 256 KB Output is correct
15 Correct 1 ms 308 KB Output is correct
16 Correct 6 ms 828 KB Output is correct
17 Correct 115 ms 12324 KB Output is correct
18 Correct 1 ms 256 KB Output is correct
19 Correct 1 ms 304 KB Output is correct
20 Correct 52 ms 5816 KB Output is correct
21 Correct 245 ms 22240 KB Output is correct
22 Correct 187 ms 22272 KB Output is correct
23 Correct 206 ms 22264 KB Output is correct
24 Correct 178 ms 22320 KB Output is correct
25 Correct 94 ms 12460 KB Output is correct
26 Correct 112 ms 12432 KB Output is correct
27 Correct 208 ms 22308 KB Output is correct
28 Correct 208 ms 22324 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 9 ms 1180 KB Output is correct
9 Correct 177 ms 22296 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 13 ms 1220 KB Output is correct
13 Correct 224 ms 22236 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 300 KB Output is correct
16 Correct 6 ms 852 KB Output is correct
17 Correct 114 ms 12396 KB Output is correct
18 Correct 1 ms 308 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 45 ms 5808 KB Output is correct
22 Correct 179 ms 22224 KB Output is correct
23 Correct 182 ms 22356 KB Output is correct
24 Correct 186 ms 22280 KB Output is correct
25 Correct 65 ms 12172 KB Output is correct
26 Correct 80 ms 12164 KB Output is correct
27 Correct 197 ms 22244 KB Output is correct
28 Correct 188 ms 22208 KB Output is correct
29 Correct 72 ms 12168 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 43 ms 5796 KB Output is correct
5 Correct 174 ms 22236 KB Output is correct
6 Correct 165 ms 22216 KB Output is correct
7 Correct 179 ms 22220 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 41 ms 5868 KB Output is correct
10 Correct 172 ms 22364 KB Output is correct
11 Correct 167 ms 22280 KB Output is correct
12 Correct 183 ms 22232 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 42 ms 5904 KB Output is correct
17 Correct 185 ms 22388 KB Output is correct
18 Correct 170 ms 22320 KB Output is correct
19 Correct 181 ms 22244 KB Output is correct
20 Correct 166 ms 22208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 300 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 308 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 9 ms 1236 KB Output is correct
7 Correct 176 ms 22264 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 12 ms 1184 KB Output is correct
13 Correct 237 ms 22312 KB Output is correct
14 Correct 1 ms 256 KB Output is correct
15 Correct 1 ms 308 KB Output is correct
16 Correct 6 ms 828 KB Output is correct
17 Correct 115 ms 12324 KB Output is correct
18 Correct 1 ms 256 KB Output is correct
19 Correct 1 ms 304 KB Output is correct
20 Correct 52 ms 5816 KB Output is correct
21 Correct 245 ms 22240 KB Output is correct
22 Correct 187 ms 22272 KB Output is correct
23 Correct 206 ms 22264 KB Output is correct
24 Correct 178 ms 22320 KB Output is correct
25 Correct 94 ms 12460 KB Output is correct
26 Correct 112 ms 12432 KB Output is correct
27 Correct 208 ms 22308 KB Output is correct
28 Correct 208 ms 22324 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 9 ms 1180 KB Output is correct
37 Correct 177 ms 22296 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 13 ms 1220 KB Output is correct
41 Correct 224 ms 22236 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 0 ms 300 KB Output is correct
44 Correct 6 ms 852 KB Output is correct
45 Correct 114 ms 12396 KB Output is correct
46 Correct 1 ms 308 KB Output is correct
47 Correct 1 ms 212 KB Output is correct
48 Correct 1 ms 212 KB Output is correct
49 Correct 45 ms 5808 KB Output is correct
50 Correct 179 ms 22224 KB Output is correct
51 Correct 182 ms 22356 KB Output is correct
52 Correct 186 ms 22280 KB Output is correct
53 Correct 65 ms 12172 KB Output is correct
54 Correct 80 ms 12164 KB Output is correct
55 Correct 197 ms 22244 KB Output is correct
56 Correct 188 ms 22208 KB Output is correct
57 Correct 72 ms 12168 KB Output is correct
58 Correct 1 ms 304 KB Output is correct
59 Correct 0 ms 212 KB Output is correct
60 Correct 4 ms 852 KB Output is correct
61 Correct 84 ms 12176 KB Output is correct
62 Correct 0 ms 212 KB Output is correct
63 Correct 1 ms 212 KB Output is correct
64 Correct 1 ms 300 KB Output is correct
65 Correct 42 ms 5900 KB Output is correct
66 Correct 71 ms 12236 KB Output is correct
67 Correct 73 ms 12168 KB Output is correct
68 Correct 72 ms 12176 KB Output is correct
69 Correct 65 ms 12236 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 300 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 308 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 9 ms 1236 KB Output is correct
7 Correct 176 ms 22264 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 12 ms 1184 KB Output is correct
13 Correct 237 ms 22312 KB Output is correct
14 Correct 1 ms 256 KB Output is correct
15 Correct 1 ms 308 KB Output is correct
16 Correct 6 ms 828 KB Output is correct
17 Correct 115 ms 12324 KB Output is correct
18 Correct 1 ms 256 KB Output is correct
19 Correct 1 ms 304 KB Output is correct
20 Correct 52 ms 5816 KB Output is correct
21 Correct 245 ms 22240 KB Output is correct
22 Correct 187 ms 22272 KB Output is correct
23 Correct 206 ms 22264 KB Output is correct
24 Correct 178 ms 22320 KB Output is correct
25 Correct 94 ms 12460 KB Output is correct
26 Correct 112 ms 12432 KB Output is correct
27 Correct 208 ms 22308 KB Output is correct
28 Correct 208 ms 22324 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 9 ms 1180 KB Output is correct
37 Correct 177 ms 22296 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 13 ms 1220 KB Output is correct
41 Correct 224 ms 22236 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 0 ms 300 KB Output is correct
44 Correct 6 ms 852 KB Output is correct
45 Correct 114 ms 12396 KB Output is correct
46 Correct 1 ms 308 KB Output is correct
47 Correct 1 ms 212 KB Output is correct
48 Correct 1 ms 212 KB Output is correct
49 Correct 45 ms 5808 KB Output is correct
50 Correct 179 ms 22224 KB Output is correct
51 Correct 182 ms 22356 KB Output is correct
52 Correct 186 ms 22280 KB Output is correct
53 Correct 65 ms 12172 KB Output is correct
54 Correct 80 ms 12164 KB Output is correct
55 Correct 197 ms 22244 KB Output is correct
56 Correct 188 ms 22208 KB Output is correct
57 Correct 72 ms 12168 KB Output is correct
58 Correct 1 ms 212 KB Output is correct
59 Correct 0 ms 212 KB Output is correct
60 Correct 0 ms 212 KB Output is correct
61 Correct 43 ms 5796 KB Output is correct
62 Correct 174 ms 22236 KB Output is correct
63 Correct 165 ms 22216 KB Output is correct
64 Correct 179 ms 22220 KB Output is correct
65 Correct 1 ms 212 KB Output is correct
66 Correct 41 ms 5868 KB Output is correct
67 Correct 172 ms 22364 KB Output is correct
68 Correct 167 ms 22280 KB Output is correct
69 Correct 183 ms 22232 KB Output is correct
70 Correct 0 ms 212 KB Output is correct
71 Correct 1 ms 212 KB Output is correct
72 Correct 1 ms 212 KB Output is correct
73 Correct 42 ms 5904 KB Output is correct
74 Correct 185 ms 22388 KB Output is correct
75 Correct 170 ms 22320 KB Output is correct
76 Correct 181 ms 22244 KB Output is correct
77 Correct 166 ms 22208 KB Output is correct
78 Correct 1 ms 304 KB Output is correct
79 Correct 0 ms 212 KB Output is correct
80 Correct 4 ms 852 KB Output is correct
81 Correct 84 ms 12176 KB Output is correct
82 Correct 0 ms 212 KB Output is correct
83 Correct 1 ms 212 KB Output is correct
84 Correct 1 ms 300 KB Output is correct
85 Correct 42 ms 5900 KB Output is correct
86 Correct 71 ms 12236 KB Output is correct
87 Correct 73 ms 12168 KB Output is correct
88 Correct 72 ms 12176 KB Output is correct
89 Correct 65 ms 12236 KB Output is correct
90 Correct 1 ms 212 KB Output is correct
91 Correct 0 ms 212 KB Output is correct
92 Correct 4 ms 852 KB Output is correct
93 Correct 68 ms 12164 KB Output is correct
94 Correct 1 ms 212 KB Output is correct
95 Correct 1 ms 212 KB Output is correct
96 Correct 1 ms 308 KB Output is correct
97 Correct 18 ms 3412 KB Output is correct
98 Correct 74 ms 12180 KB Output is correct
99 Correct 71 ms 12288 KB Output is correct
100 Correct 86 ms 12160 KB Output is correct
101 Correct 65 ms 12168 KB Output is correct
102 Correct 72 ms 12180 KB Output is correct
103 Correct 71 ms 12240 KB Output is correct
104 Correct 73 ms 12168 KB Output is correct
105 Correct 78 ms 12168 KB Output is correct