Submission #1051378

# Submission time Handle Problem Language Result Execution time Memory
1051378 2024-08-10T05:34:56 Z Gromp15 Connecting Supertrees (IOI20_supertrees) C++17
96 / 100
113 ms 24196 KB
#include <bits/stdc++.h>
#include "supertrees.h"
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
using namespace std;

struct dsu {
	vector<int> p, size;
	dsu(int n) : p(n), size(n, 1) {
		iota(all(p), 0);
	}
	int get(int v) {
		return v == p[v] ? v : p[v] = get(p[v]);
	}
	bool merge(int a, int b) {
		a = get(a), b = get(b);
		if (a == b) return 0;
		if (size[a] < size[b]) swap(a, b);
		size[a] += size[b], p[b] = a;
		return 1;
	}
};

int construct(std::vector<std::vector<int>> p) {
	int n = sz(p);
	dsu d(n), d2(n), d3(n);
	for (int i = 0; i < n; i++) for (int j = i+1; j < n; j++) {
		if (p[i][j]) d.merge(i, j);
		if (p[i][j] == 1) d2.merge(i, j);
		if (p[i][j] == 2) d3.merge(i, j);
	}
	for (int i = 0; i < n; i++) for (int j = i+1; j < n; j++) if (!p[i][j] && d.get(i) == d.get(j)) return 0;
	vector<vector<int>> ans(n, vector<int>(n));
	vector<int> leaders;
	for (int i = 0; i < n; i++) { 
		if (i == d2.get(i)) leaders.emplace_back(i);
		else ans[i][d2.get(i)] = ans[d2.get(i)][i] = 1;
	}
	vector<vector<int>> comp(n);
	for (int v : leaders) comp[d3.get(v)].emplace_back(v);
	for (int i = 0; i < n; i++) if (comp[i].size() > 1) {
		if (comp[i].size() == 2) return 0;
		for (int j = 0; j < sz(comp[i]); j++) {
			int v = comp[i][j], u = comp[i][(j+1)%sz(comp[i])];
			ans[v][u] = ans[u][v] = 1;
		}
	}
	build(ans);
	return 1;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 5 ms 1308 KB Output is correct
7 Correct 96 ms 22156 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 5 ms 1308 KB Output is correct
7 Correct 96 ms 22156 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 432 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 4 ms 1116 KB Output is correct
13 Correct 92 ms 22100 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 2 ms 604 KB Output is correct
17 Correct 55 ms 8212 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 29 ms 5768 KB Output is correct
21 Correct 95 ms 22096 KB Output is correct
22 Correct 94 ms 22096 KB Output is correct
23 Correct 99 ms 22036 KB Output is correct
24 Correct 92 ms 22096 KB Output is correct
25 Correct 41 ms 8276 KB Output is correct
26 Correct 42 ms 8272 KB Output is correct
27 Correct 98 ms 22100 KB Output is correct
28 Correct 93 ms 22052 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 376 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 4 ms 1376 KB Output is correct
9 Correct 93 ms 24068 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 604 KB Output is correct
12 Correct 4 ms 1388 KB Output is correct
13 Correct 94 ms 24152 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 2 ms 604 KB Output is correct
17 Correct 48 ms 10104 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 23 ms 6256 KB Output is correct
22 Correct 96 ms 24144 KB Output is correct
23 Correct 97 ms 24148 KB Output is correct
24 Correct 98 ms 24196 KB Output is correct
25 Correct 41 ms 14160 KB Output is correct
26 Correct 41 ms 10248 KB Output is correct
27 Correct 94 ms 24144 KB Output is correct
28 Correct 98 ms 24144 KB Output is correct
29 Correct 41 ms 14164 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 24 ms 6312 KB Output is correct
5 Correct 94 ms 24148 KB Output is correct
6 Correct 92 ms 24196 KB Output is correct
7 Correct 99 ms 24152 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 33 ms 6236 KB Output is correct
10 Correct 113 ms 24148 KB Output is correct
11 Correct 104 ms 23888 KB Output is correct
12 Correct 100 ms 23972 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 25 ms 6276 KB Output is correct
17 Correct 112 ms 23984 KB Output is correct
18 Correct 107 ms 24152 KB Output is correct
19 Correct 93 ms 24076 KB Output is correct
20 Correct 93 ms 24060 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 5 ms 1308 KB Output is correct
7 Correct 96 ms 22156 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 432 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 4 ms 1116 KB Output is correct
13 Correct 92 ms 22100 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 2 ms 604 KB Output is correct
17 Correct 55 ms 8212 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 29 ms 5768 KB Output is correct
21 Correct 95 ms 22096 KB Output is correct
22 Correct 94 ms 22096 KB Output is correct
23 Correct 99 ms 22036 KB Output is correct
24 Correct 92 ms 22096 KB Output is correct
25 Correct 41 ms 8276 KB Output is correct
26 Correct 42 ms 8272 KB Output is correct
27 Correct 98 ms 22100 KB Output is correct
28 Correct 93 ms 22052 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 376 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 4 ms 1376 KB Output is correct
37 Correct 93 ms 24068 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 604 KB Output is correct
40 Correct 4 ms 1388 KB Output is correct
41 Correct 94 ms 24152 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 2 ms 604 KB Output is correct
45 Correct 48 ms 10104 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 23 ms 6256 KB Output is correct
50 Correct 96 ms 24144 KB Output is correct
51 Correct 97 ms 24148 KB Output is correct
52 Correct 98 ms 24196 KB Output is correct
53 Correct 41 ms 14160 KB Output is correct
54 Correct 41 ms 10248 KB Output is correct
55 Correct 94 ms 24144 KB Output is correct
56 Correct 98 ms 24144 KB Output is correct
57 Correct 41 ms 14164 KB Output is correct
58 Correct 0 ms 344 KB Output is correct
59 Correct 0 ms 348 KB Output is correct
60 Correct 2 ms 604 KB Output is correct
61 Correct 46 ms 10164 KB Output is correct
62 Correct 0 ms 348 KB Output is correct
63 Correct 0 ms 348 KB Output is correct
64 Correct 1 ms 348 KB Output is correct
65 Correct 34 ms 6260 KB Output is correct
66 Correct 41 ms 10068 KB Output is correct
67 Correct 41 ms 10064 KB Output is correct
68 Correct 39 ms 10068 KB Output is correct
69 Correct 41 ms 14160 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 5 ms 1308 KB Output is correct
7 Correct 96 ms 22156 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 432 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 4 ms 1116 KB Output is correct
13 Correct 92 ms 22100 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 2 ms 604 KB Output is correct
17 Correct 55 ms 8212 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 29 ms 5768 KB Output is correct
21 Correct 95 ms 22096 KB Output is correct
22 Correct 94 ms 22096 KB Output is correct
23 Correct 99 ms 22036 KB Output is correct
24 Correct 92 ms 22096 KB Output is correct
25 Correct 41 ms 8276 KB Output is correct
26 Correct 42 ms 8272 KB Output is correct
27 Correct 98 ms 22100 KB Output is correct
28 Correct 93 ms 22052 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 376 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 4 ms 1376 KB Output is correct
37 Correct 93 ms 24068 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 604 KB Output is correct
40 Correct 4 ms 1388 KB Output is correct
41 Correct 94 ms 24152 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 2 ms 604 KB Output is correct
45 Correct 48 ms 10104 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 23 ms 6256 KB Output is correct
50 Correct 96 ms 24144 KB Output is correct
51 Correct 97 ms 24148 KB Output is correct
52 Correct 98 ms 24196 KB Output is correct
53 Correct 41 ms 14160 KB Output is correct
54 Correct 41 ms 10248 KB Output is correct
55 Correct 94 ms 24144 KB Output is correct
56 Correct 98 ms 24144 KB Output is correct
57 Correct 41 ms 14164 KB Output is correct
58 Correct 1 ms 348 KB Output is correct
59 Correct 0 ms 348 KB Output is correct
60 Correct 0 ms 348 KB Output is correct
61 Correct 24 ms 6312 KB Output is correct
62 Correct 94 ms 24148 KB Output is correct
63 Correct 92 ms 24196 KB Output is correct
64 Correct 99 ms 24152 KB Output is correct
65 Correct 0 ms 344 KB Output is correct
66 Correct 33 ms 6236 KB Output is correct
67 Correct 113 ms 24148 KB Output is correct
68 Correct 104 ms 23888 KB Output is correct
69 Correct 100 ms 23972 KB Output is correct
70 Correct 0 ms 348 KB Output is correct
71 Correct 0 ms 348 KB Output is correct
72 Correct 0 ms 348 KB Output is correct
73 Correct 25 ms 6276 KB Output is correct
74 Correct 112 ms 23984 KB Output is correct
75 Correct 107 ms 24152 KB Output is correct
76 Correct 93 ms 24076 KB Output is correct
77 Correct 93 ms 24060 KB Output is correct
78 Correct 0 ms 344 KB Output is correct
79 Correct 0 ms 348 KB Output is correct
80 Correct 2 ms 604 KB Output is correct
81 Correct 46 ms 10164 KB Output is correct
82 Correct 0 ms 348 KB Output is correct
83 Correct 0 ms 348 KB Output is correct
84 Correct 1 ms 348 KB Output is correct
85 Correct 34 ms 6260 KB Output is correct
86 Correct 41 ms 10068 KB Output is correct
87 Correct 41 ms 10064 KB Output is correct
88 Correct 39 ms 10068 KB Output is correct
89 Correct 41 ms 14160 KB Output is correct
90 Correct 0 ms 348 KB Output is correct
91 Correct 0 ms 348 KB Output is correct
92 Correct 4 ms 604 KB Output is correct
93 Correct 53 ms 10064 KB Output is correct
94 Incorrect 0 ms 344 KB Answer gives possible 1 while actual possible 0
95 Halted 0 ms 0 KB -