Skip to content

Commit 9d3aaaf

Browse files
lrvideckisweb-flow
andauthored
golf (#92)
* golf * [auto-verifier] verify commit a77a224 * add asserts for par cent --------- Co-authored-by: GitHub <[email protected]>
1 parent 3b21c06 commit 9d3aaaf

File tree

3 files changed

+21
-23
lines changed

3 files changed

+21
-23
lines changed

.verify-helper/timestamps.remote.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
"tests/library_checker_aizu_tests/graphs/strongly_connected_components_aizu.test.cpp": "2024-10-19 22:41:15 -0700",
6767
"tests/library_checker_aizu_tests/graphs/strongly_connected_components_lib_checker.test.cpp": "2024-10-19 22:41:15 -0700",
6868
"tests/library_checker_aizu_tests/graphs/two_edge_components.test.cpp": "2024-10-19 01:05:18 -0700",
69-
"tests/library_checker_aizu_tests/handmade_tests/count_paths_forest.test.cpp": "2024-10-29 23:57:39 -0700",
69+
"tests/library_checker_aizu_tests/handmade_tests/count_paths_forest.test.cpp": "2024-11-07 09:34:29 -0600",
7070
"tests/library_checker_aizu_tests/handmade_tests/dsu_size.test.cpp": "2024-10-19 22:41:15 -0700",
7171
"tests/library_checker_aizu_tests/handmade_tests/edge_cd_small_trees.test.cpp": "2024-10-19 01:05:18 -0700",
7272
"tests/library_checker_aizu_tests/handmade_tests/fib_matrix_expo.test.cpp": "2024-10-19 22:41:15 -0700",
@@ -132,9 +132,9 @@
132132
"tests/library_checker_aizu_tests/strings/suffix_array.test.cpp": "2024-10-19 22:41:15 -0700",
133133
"tests/library_checker_aizu_tests/strings/trie.test.cpp": "2024-10-19 01:05:18 -0700",
134134
"tests/library_checker_aizu_tests/strings/wildcard_pattern_matching.test.cpp": "2024-10-19 01:05:18 -0700",
135-
"tests/library_checker_aizu_tests/trees/cd_jump_on_tree.test.cpp": "2024-10-29 23:57:39 -0700",
136-
"tests/library_checker_aizu_tests/trees/cd_lca.test.cpp": "2024-10-29 23:57:39 -0700",
137-
"tests/library_checker_aizu_tests/trees/count_paths_per_length.test.cpp": "2024-10-29 23:57:39 -0700",
135+
"tests/library_checker_aizu_tests/trees/cd_jump_on_tree.test.cpp": "2024-11-07 09:34:29 -0600",
136+
"tests/library_checker_aizu_tests/trees/cd_lca.test.cpp": "2024-11-07 09:34:29 -0600",
137+
"tests/library_checker_aizu_tests/trees/count_paths_per_length.test.cpp": "2024-11-07 09:34:29 -0600",
138138
"tests/library_checker_aizu_tests/trees/edge_cd_contour_range_query.test.cpp": "2024-10-19 22:41:15 -0700",
139139
"tests/library_checker_aizu_tests/trees/edge_cd_contour_range_update.test.cpp": "2024-10-19 22:41:15 -0700",
140140
"tests/library_checker_aizu_tests/trees/edge_cd_count_paths_per_length.test.cpp": "2024-10-19 01:05:18 -0700",

library/trees/centroid_decomp.hpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,21 @@
99
template<class F> struct centroid {
1010
vector<vi> adj;
1111
F f;
12-
vi sub_sz;
12+
vi siz;
1313
centroid(const vector<vi>& a_adj, F a_f):
14-
adj(a_adj), f(a_f), sub_sz(sz(adj), -1) {
15-
rep(i, 0, sz(adj)) if (sub_sz[i] == -1) dfs(i, -1);
14+
adj(a_adj), f(a_f), siz(sz(adj), -1) {
15+
rep(i, 0, sz(adj)) if (siz[i] == -1) dfs(i, -1);
1616
}
1717
void calc_sz(int v, int p) {
18-
sub_sz[v] = 1;
18+
siz[v] = 1;
1919
for (int u : adj[v])
20-
if (u != p) calc_sz(u, v), sub_sz[v] += sub_sz[u];
20+
if (u != p) calc_sz(u, v), siz[v] += siz[u];
2121
}
2222
void dfs(int v, int p) {
2323
calc_sz(v, -1);
24-
for (int w = -1, sz_root = sub_sz[v];;) {
24+
for (int w = -1, sz_root = siz[v];;) {
2525
auto big_ch = find_if(all(adj[v]), [&](int u) {
26-
return u != w && 2 * sub_sz[u] > sz_root;
26+
return u != w && 2 * siz[u] > sz_root;
2727
});
2828
if (big_ch == end(adj[v])) break;
2929
w = v, v = *big_ch;
Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,26 @@
11
#pragma once
22
#include "../../library/trees/centroid_decomp.hpp"
33
void cd_asserts(const vector<vector<int>>& adj) {
4-
vector<bool> seen_cent(sz(adj));
4+
vector<int> decomp_size(sz(adj), -1);
55
centroid(adj,
66
[&](const vector<vector<int>>& cd_adj, int cent,
7-
int) -> void {
8-
assert(!seen_cent[cent]);
9-
seen_cent[cent] = 1;
7+
int par_cent) -> void {
8+
assert(decomp_size[cent] == -1);
109
auto dfs = [&](auto&& self, int u, int p) -> int {
1110
int sub_size = 1;
1211
for (int v : cd_adj[u])
1312
if (v != p) sub_size += self(self, v, u);
1413
return sub_size;
1514
};
16-
int sz_decomp = dfs(dfs, cent, -1);
17-
int sum = 1;
15+
decomp_size[cent] = dfs(dfs, cent, -1);
16+
if (par_cent != -1)
17+
assert(1 <= decomp_size[cent] &&
18+
2 * decomp_size[cent] <= decomp_size[par_cent]);
1819
for (int u : cd_adj[cent]) {
1920
int sz_subtree = dfs(dfs, u, cent);
20-
sum += sz_subtree;
21-
assert(
22-
1 <= sz_subtree && 2 * sz_subtree <= sz_decomp);
21+
assert(1 <= sz_subtree &&
22+
2 * sz_subtree <= decomp_size[cent]);
2323
}
24-
assert(sum == sz_decomp);
2524
});
26-
assert(find(begin(seen_cent), end(seen_cent), 0) ==
27-
end(seen_cent));
25+
rep(i, 0, sz(adj)) assert(decomp_size[i] >= 1);
2826
}

0 commit comments

Comments
 (0)