Submission #300687

# Submission time Handle Problem Language Result Execution time Memory
300687 2020-09-17T11:59:48 Z Temmie Connecting Supertrees (IOI20_supertrees) C++17
100 / 100
327 ms 26360 KB
#include <bits/stdc++.h>

void build(std::vector <std::vector <int>> b);

void ff1(int node, int n, std::vector <std::vector <int>>& p, std::vector <std::vector <int>>& col, std::vector <bool>& vis) {
	if (vis[node]) return;
	vis[node] = true;
	col.back().push_back(node);
	for (int i = 0; i < n; i++) {
		if (p[node][i] == 1) {
			ff1(i, n, p, col, vis);
		}
	}
}

void ff2(int node, int n, std::vector <std::vector <int>>& p, std::vector <std::vector <int>>& col, std::vector <bool>& vis) {
	if (vis[node]) return;
	vis[node] = true;
	col.back().push_back(node);
	for (int i = 0; i < n; i++) {
		if (p[node][i] == 2) {
			ff2(i, n, p, col, vis);
		}
	}
}

void dfs(int node, int n, std::vector <bool>& vis, std::vector <int>& cnt, std::vector <std::vector <int>>& g) {
	if (vis[node]) return;
	vis[node] = true;
	cnt[node]++;
	for (int x : g[node]) {
		dfs(x, n, vis, cnt, g);
	}
	vis[node] = false;
}

int construct(std::vector <std::vector <int>> p) {
	
	std::vector <std::vector <int>> ep(p);
	int n = p.size();
	std::vector <std::vector <int>> ocol;
	for (int i = 0; i < n; i++) {
		static std::vector <bool> vis(n, false);
		if (vis[i]) continue;
		for (int j = i + 1; j < n; j++) {
			if (p[i][j] == 1) {
				ocol.push_back({ });
				ff1(i, n, p, ocol, vis);
				break;
			}
		}
	}
	for (auto& v : ocol) {
		for (size_t i = 1; i < v.size(); i++) {
			for (int j = 0; j < n; j++) {
				p[v[i]][j] = p[j][v[i]] = 0;
			}
			p[v[i]][v[i]] = 1;
		}
	}
	std::vector <std::vector <int>> tcol;
	for (int i = 0; i < n; i++) {
		static std::vector <bool> vis(n, false);
		if (vis[i]) continue;
		for (int j = i + 1; j < n; j++) {
			if (p[i][j] == 2) {
				tcol.push_back({ });
				ff2(i, n, p, tcol, vis);
				break;
			}
		}
	}
	std::vector <std::vector <int>> ans(n, std::vector <int> (n, 0));
	for (auto& v : ocol) {
		for (size_t i = 0; i < v.size() - 1; i++) {
			ans[v[i]][v[i + 1]] = ans[v[i + 1]][v[i]] = 1;
		}
	}
	for (auto& v : tcol) {
		for (size_t i = 0; i < v.size() - 1; i++) {
			ans[v[i]][v[i + 1]] = ans[v[i + 1]][v[i]] = 1;
		}
		ans[v[0]][v.back()] = ans[v.back()][v[0]] = 1;
	}
	std::vector <std::vector <int>> adj(n);
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if (ans[i][j]) adj[i].push_back(j);
		}
	}
	for (int i = 0; i < n; i++) {
		std::vector <bool> vis(n, false);
		std::vector <int> cnt(n, 0);
		dfs(i, n, vis, cnt, adj);
		for (int j = 0; j < n; j++) {
			if (ep[i][j] != cnt[j]) return 0;
		}
	}
	build(ans);
	return 1;
	
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 12 ms 1408 KB Output is correct
7 Correct 279 ms 26360 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 12 ms 1408 KB Output is correct
7 Correct 279 ms 26360 KB Output is correct
8 Correct 1 ms 256 KB Output is correct
9 Correct 1 ms 256 KB Output is correct
10 Correct 1 ms 256 KB Output is correct
11 Correct 1 ms 256 KB Output is correct
12 Correct 10 ms 1408 KB Output is correct
13 Correct 245 ms 26160 KB Output is correct
14 Correct 1 ms 256 KB Output is correct
15 Correct 1 ms 256 KB Output is correct
16 Correct 6 ms 928 KB Output is correct
17 Correct 128 ms 16248 KB Output is correct
18 Correct 1 ms 256 KB Output is correct
19 Correct 0 ms 256 KB Output is correct
20 Correct 63 ms 6776 KB Output is correct
21 Correct 255 ms 26104 KB Output is correct
22 Correct 244 ms 26104 KB Output is correct
23 Correct 270 ms 26104 KB Output is correct
24 Correct 265 ms 26104 KB Output is correct
25 Correct 130 ms 16120 KB Output is correct
26 Correct 109 ms 16248 KB Output is correct
27 Correct 290 ms 26104 KB Output is correct
28 Correct 242 ms 26080 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 1 ms 256 KB Output is correct
7 Correct 1 ms 256 KB Output is correct
8 Correct 10 ms 1408 KB Output is correct
9 Correct 241 ms 26108 KB Output is correct
10 Correct 1 ms 256 KB Output is correct
11 Correct 1 ms 256 KB Output is correct
12 Correct 12 ms 1408 KB Output is correct
13 Correct 327 ms 26232 KB Output is correct
14 Correct 1 ms 256 KB Output is correct
15 Correct 1 ms 256 KB Output is correct
16 Correct 6 ms 1024 KB Output is correct
17 Correct 130 ms 16216 KB Output is correct
18 Correct 1 ms 256 KB Output is correct
19 Correct 1 ms 256 KB Output is correct
20 Correct 1 ms 256 KB Output is correct
21 Correct 62 ms 6776 KB Output is correct
22 Correct 252 ms 26196 KB Output is correct
23 Correct 245 ms 26076 KB Output is correct
24 Correct 269 ms 26072 KB Output is correct
25 Correct 106 ms 16160 KB Output is correct
26 Correct 104 ms 16124 KB Output is correct
27 Correct 245 ms 26104 KB Output is correct
28 Correct 279 ms 26200 KB Output is correct
29 Correct 106 ms 16120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 73 ms 6776 KB Output is correct
5 Correct 281 ms 26072 KB Output is correct
6 Correct 263 ms 26168 KB Output is correct
7 Correct 278 ms 26080 KB Output is correct
8 Correct 1 ms 256 KB Output is correct
9 Correct 63 ms 6780 KB Output is correct
10 Correct 251 ms 26196 KB Output is correct
11 Correct 255 ms 26068 KB Output is correct
12 Correct 297 ms 26104 KB Output is correct
13 Correct 1 ms 256 KB Output is correct
14 Correct 1 ms 256 KB Output is correct
15 Correct 1 ms 256 KB Output is correct
16 Correct 66 ms 6836 KB Output is correct
17 Correct 278 ms 26104 KB Output is correct
18 Correct 259 ms 26104 KB Output is correct
19 Correct 254 ms 26104 KB Output is correct
20 Correct 247 ms 26108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 12 ms 1408 KB Output is correct
7 Correct 279 ms 26360 KB Output is correct
8 Correct 1 ms 256 KB Output is correct
9 Correct 1 ms 256 KB Output is correct
10 Correct 1 ms 256 KB Output is correct
11 Correct 1 ms 256 KB Output is correct
12 Correct 10 ms 1408 KB Output is correct
13 Correct 245 ms 26160 KB Output is correct
14 Correct 1 ms 256 KB Output is correct
15 Correct 1 ms 256 KB Output is correct
16 Correct 6 ms 928 KB Output is correct
17 Correct 128 ms 16248 KB Output is correct
18 Correct 1 ms 256 KB Output is correct
19 Correct 0 ms 256 KB Output is correct
20 Correct 63 ms 6776 KB Output is correct
21 Correct 255 ms 26104 KB Output is correct
22 Correct 244 ms 26104 KB Output is correct
23 Correct 270 ms 26104 KB Output is correct
24 Correct 265 ms 26104 KB Output is correct
25 Correct 130 ms 16120 KB Output is correct
26 Correct 109 ms 16248 KB Output is correct
27 Correct 290 ms 26104 KB Output is correct
28 Correct 242 ms 26080 KB Output is correct
29 Correct 1 ms 256 KB Output is correct
30 Correct 1 ms 256 KB Output is correct
31 Correct 1 ms 256 KB Output is correct
32 Correct 1 ms 256 KB Output is correct
33 Correct 1 ms 256 KB Output is correct
34 Correct 1 ms 256 KB Output is correct
35 Correct 1 ms 256 KB Output is correct
36 Correct 10 ms 1408 KB Output is correct
37 Correct 241 ms 26108 KB Output is correct
38 Correct 1 ms 256 KB Output is correct
39 Correct 1 ms 256 KB Output is correct
40 Correct 12 ms 1408 KB Output is correct
41 Correct 327 ms 26232 KB Output is correct
42 Correct 1 ms 256 KB Output is correct
43 Correct 1 ms 256 KB Output is correct
44 Correct 6 ms 1024 KB Output is correct
45 Correct 130 ms 16216 KB Output is correct
46 Correct 1 ms 256 KB Output is correct
47 Correct 1 ms 256 KB Output is correct
48 Correct 1 ms 256 KB Output is correct
49 Correct 62 ms 6776 KB Output is correct
50 Correct 252 ms 26196 KB Output is correct
51 Correct 245 ms 26076 KB Output is correct
52 Correct 269 ms 26072 KB Output is correct
53 Correct 106 ms 16160 KB Output is correct
54 Correct 104 ms 16124 KB Output is correct
55 Correct 245 ms 26104 KB Output is correct
56 Correct 279 ms 26200 KB Output is correct
57 Correct 106 ms 16120 KB Output is correct
58 Correct 1 ms 256 KB Output is correct
59 Correct 0 ms 256 KB Output is correct
60 Correct 7 ms 1024 KB Output is correct
61 Correct 125 ms 16248 KB Output is correct
62 Correct 1 ms 256 KB Output is correct
63 Correct 1 ms 256 KB Output is correct
64 Correct 1 ms 256 KB Output is correct
65 Correct 63 ms 6776 KB Output is correct
66 Correct 108 ms 16120 KB Output is correct
67 Correct 115 ms 16120 KB Output is correct
68 Correct 110 ms 16120 KB Output is correct
69 Correct 134 ms 16120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 12 ms 1408 KB Output is correct
7 Correct 279 ms 26360 KB Output is correct
8 Correct 1 ms 256 KB Output is correct
9 Correct 1 ms 256 KB Output is correct
10 Correct 1 ms 256 KB Output is correct
11 Correct 1 ms 256 KB Output is correct
12 Correct 10 ms 1408 KB Output is correct
13 Correct 245 ms 26160 KB Output is correct
14 Correct 1 ms 256 KB Output is correct
15 Correct 1 ms 256 KB Output is correct
16 Correct 6 ms 928 KB Output is correct
17 Correct 128 ms 16248 KB Output is correct
18 Correct 1 ms 256 KB Output is correct
19 Correct 0 ms 256 KB Output is correct
20 Correct 63 ms 6776 KB Output is correct
21 Correct 255 ms 26104 KB Output is correct
22 Correct 244 ms 26104 KB Output is correct
23 Correct 270 ms 26104 KB Output is correct
24 Correct 265 ms 26104 KB Output is correct
25 Correct 130 ms 16120 KB Output is correct
26 Correct 109 ms 16248 KB Output is correct
27 Correct 290 ms 26104 KB Output is correct
28 Correct 242 ms 26080 KB Output is correct
29 Correct 1 ms 256 KB Output is correct
30 Correct 1 ms 256 KB Output is correct
31 Correct 1 ms 256 KB Output is correct
32 Correct 1 ms 256 KB Output is correct
33 Correct 1 ms 256 KB Output is correct
34 Correct 1 ms 256 KB Output is correct
35 Correct 1 ms 256 KB Output is correct
36 Correct 10 ms 1408 KB Output is correct
37 Correct 241 ms 26108 KB Output is correct
38 Correct 1 ms 256 KB Output is correct
39 Correct 1 ms 256 KB Output is correct
40 Correct 12 ms 1408 KB Output is correct
41 Correct 327 ms 26232 KB Output is correct
42 Correct 1 ms 256 KB Output is correct
43 Correct 1 ms 256 KB Output is correct
44 Correct 6 ms 1024 KB Output is correct
45 Correct 130 ms 16216 KB Output is correct
46 Correct 1 ms 256 KB Output is correct
47 Correct 1 ms 256 KB Output is correct
48 Correct 1 ms 256 KB Output is correct
49 Correct 62 ms 6776 KB Output is correct
50 Correct 252 ms 26196 KB Output is correct
51 Correct 245 ms 26076 KB Output is correct
52 Correct 269 ms 26072 KB Output is correct
53 Correct 106 ms 16160 KB Output is correct
54 Correct 104 ms 16124 KB Output is correct
55 Correct 245 ms 26104 KB Output is correct
56 Correct 279 ms 26200 KB Output is correct
57 Correct 106 ms 16120 KB Output is correct
58 Correct 1 ms 256 KB Output is correct
59 Correct 1 ms 256 KB Output is correct
60 Correct 0 ms 256 KB Output is correct
61 Correct 73 ms 6776 KB Output is correct
62 Correct 281 ms 26072 KB Output is correct
63 Correct 263 ms 26168 KB Output is correct
64 Correct 278 ms 26080 KB Output is correct
65 Correct 1 ms 256 KB Output is correct
66 Correct 63 ms 6780 KB Output is correct
67 Correct 251 ms 26196 KB Output is correct
68 Correct 255 ms 26068 KB Output is correct
69 Correct 297 ms 26104 KB Output is correct
70 Correct 1 ms 256 KB Output is correct
71 Correct 1 ms 256 KB Output is correct
72 Correct 1 ms 256 KB Output is correct
73 Correct 66 ms 6836 KB Output is correct
74 Correct 278 ms 26104 KB Output is correct
75 Correct 259 ms 26104 KB Output is correct
76 Correct 254 ms 26104 KB Output is correct
77 Correct 247 ms 26108 KB Output is correct
78 Correct 1 ms 256 KB Output is correct
79 Correct 0 ms 256 KB Output is correct
80 Correct 7 ms 1024 KB Output is correct
81 Correct 125 ms 16248 KB Output is correct
82 Correct 1 ms 256 KB Output is correct
83 Correct 1 ms 256 KB Output is correct
84 Correct 1 ms 256 KB Output is correct
85 Correct 63 ms 6776 KB Output is correct
86 Correct 108 ms 16120 KB Output is correct
87 Correct 115 ms 16120 KB Output is correct
88 Correct 110 ms 16120 KB Output is correct
89 Correct 134 ms 16120 KB Output is correct
90 Correct 0 ms 256 KB Output is correct
91 Correct 1 ms 256 KB Output is correct
92 Correct 5 ms 1024 KB Output is correct
93 Correct 129 ms 16216 KB Output is correct
94 Correct 1 ms 256 KB Output is correct
95 Correct 1 ms 256 KB Output is correct
96 Correct 0 ms 256 KB Output is correct
97 Correct 31 ms 4472 KB Output is correct
98 Correct 109 ms 16248 KB Output is correct
99 Correct 111 ms 16252 KB Output is correct
100 Correct 110 ms 16120 KB Output is correct
101 Correct 136 ms 16120 KB Output is correct
102 Correct 107 ms 16120 KB Output is correct
103 Correct 116 ms 16248 KB Output is correct
104 Correct 125 ms 16216 KB Output is correct
105 Correct 110 ms 16084 KB Output is correct