Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 40 additions & 40 deletions .verify-helper/timestamps.remote.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"tests/library_checker_aizu_tests/convolution/gcd_convolution.test.cpp": "2026-07-06 13:10:16 -0700",
"tests/library_checker_aizu_tests/convolution/lcm_convolution.test.cpp": "2026-07-06 13:10:16 -0700",
"tests/library_checker_aizu_tests/convolution/min_plus_convolution.test.cpp": "2026-07-06 13:10:16 -0700",
"tests/library_checker_aizu_tests/convolution/min_plus_convolution.test.cpp": "2026-07-06 22:52:18 -0700",
"tests/library_checker_aizu_tests/convolution/xor_convolution.test.cpp": "2026-07-06 13:10:16 -0700",
"tests/library_checker_aizu_tests/data_structures/binary_search_example.test.cpp": "2026-07-06 13:10:16 -0700",
"tests/library_checker_aizu_tests/data_structures/binary_trie.test.cpp": "2026-07-06 11:00:20 -0700",
Expand Down Expand Up @@ -30,7 +30,7 @@
"tests/library_checker_aizu_tests/data_structures/lazy_segment_tree_inc_constructor.test.cpp": "2026-07-06 13:10:16 -0700",
"tests/library_checker_aizu_tests/data_structures/merge_sort_tree.test.cpp": "2026-07-06 13:10:16 -0700",
"tests/library_checker_aizu_tests/data_structures/mode_query.test.cpp": "2026-07-06 13:10:16 -0700",
"tests/library_checker_aizu_tests/data_structures/permutation_tree.test.cpp": "2026-07-06 22:18:09 -0700",
"tests/library_checker_aizu_tests/data_structures/permutation_tree.test.cpp": "2026-07-07 09:17:02 -0700",
"tests/library_checker_aizu_tests/data_structures/persistent_queue_tree.test.cpp": "2026-07-06 13:10:16 -0700",
"tests/library_checker_aizu_tests/data_structures/persistent_seg_tree.test.cpp": "2026-07-06 13:10:16 -0700",
"tests/library_checker_aizu_tests/data_structures/pq_ds_undo_sliding_window.test.cpp": "2026-07-06 13:10:16 -0700",
Expand All @@ -49,39 +49,39 @@
"tests/library_checker_aizu_tests/dsu/dsu_bipartite.test.cpp": "2026-07-06 13:10:16 -0700",
"tests/library_checker_aizu_tests/dsu/dsu_weighted_aizu.test.cpp": "2026-07-06 13:49:19 -0700",
"tests/library_checker_aizu_tests/dsu/dsu_weighted_lib_checker.test.cpp": "2026-07-06 13:49:19 -0700",
"tests/library_checker_aizu_tests/dsu/kruskal_tree_aizu.test.cpp": "2026-07-06 22:18:09 -0700",
"tests/library_checker_aizu_tests/dsu/kruskal_tree_aizu.test.cpp": "2026-07-07 09:17:02 -0700",
"tests/library_checker_aizu_tests/dsu/line_tree_aizu.test.cpp": "2026-07-06 13:10:16 -0700",
"tests/library_checker_aizu_tests/dsu/line_tree_lib_checker.test.cpp": "2026-07-06 13:10:16 -0700",
"tests/library_checker_aizu_tests/dsu/range_parallel_dsu.test.cpp": "2026-07-06 13:10:16 -0700",
"tests/library_checker_aizu_tests/flow/hungarian.test.cpp": "2026-07-06 13:09:48 -0700",
"tests/library_checker_aizu_tests/flow/min_cost_max_flow.test.cpp": "2026-04-06 14:41:55 -0600",
"tests/library_checker_aizu_tests/graphs/bcc_callback_aizu_bcc.test.cpp": "2026-07-06 13:10:16 -0700",
"tests/library_checker_aizu_tests/graphs/bcc_callback_aizu_two_edge_cc.test.cpp": "2026-07-06 13:10:16 -0700",
"tests/library_checker_aizu_tests/graphs/bcc_callback_lib_checker_bcc.test.cpp": "2026-07-06 13:10:16 -0700",
"tests/library_checker_aizu_tests/graphs/bcc_callback_lib_checker_two_cc.test.cpp": "2026-07-06 13:10:16 -0700",
"tests/library_checker_aizu_tests/graphs/biconnected_components.test.cpp": "2026-07-06 13:10:16 -0700",
"tests/library_checker_aizu_tests/graphs/bcc_callback_aizu_bcc.test.cpp": "2026-07-06 22:30:55 -0700",
"tests/library_checker_aizu_tests/graphs/bcc_callback_aizu_two_edge_cc.test.cpp": "2026-07-06 22:30:55 -0700",
"tests/library_checker_aizu_tests/graphs/bcc_callback_lib_checker_bcc.test.cpp": "2026-07-06 22:30:55 -0700",
"tests/library_checker_aizu_tests/graphs/bcc_callback_lib_checker_two_cc.test.cpp": "2026-07-06 22:30:55 -0700",
"tests/library_checker_aizu_tests/graphs/biconnected_components.test.cpp": "2026-07-06 22:30:55 -0700",
"tests/library_checker_aizu_tests/graphs/connected_components_of_complement_graph.test.cpp": "2026-07-06 13:10:16 -0700",
"tests/library_checker_aizu_tests/graphs/dijkstra_aizu.test.cpp": "2026-07-06 13:10:16 -0700",
"tests/library_checker_aizu_tests/graphs/dijkstra_lib_checker.test.cpp": "2026-07-06 22:18:09 -0700",
"tests/library_checker_aizu_tests/graphs/directed_cycle.test.cpp": "2026-07-06 13:10:16 -0700",
"tests/library_checker_aizu_tests/graphs/dijkstra_lib_checker.test.cpp": "2026-07-07 09:17:02 -0700",
"tests/library_checker_aizu_tests/graphs/directed_cycle.test.cpp": "2026-07-06 22:30:55 -0700",
"tests/library_checker_aizu_tests/graphs/enumerate_triangles.test.cpp": "2026-07-06 13:10:16 -0700",
"tests/library_checker_aizu_tests/graphs/euler_walk_directed.test.cpp": "2026-07-06 13:10:16 -0700",
"tests/library_checker_aizu_tests/graphs/euler_walk_undirected.test.cpp": "2026-07-06 13:10:16 -0700",
"tests/library_checker_aizu_tests/graphs/euler_walk_directed.test.cpp": "2026-07-06 22:30:55 -0700",
"tests/library_checker_aizu_tests/graphs/euler_walk_undirected.test.cpp": "2026-07-06 22:30:55 -0700",
"tests/library_checker_aizu_tests/graphs/hopcroft_karp_aizu.test.cpp": "2026-07-06 13:10:16 -0700",
"tests/library_checker_aizu_tests/graphs/hopcroft_karp_lib_checker.test.cpp": "2026-07-06 13:10:16 -0700",
"tests/library_checker_aizu_tests/graphs/mst.test.cpp": "2026-07-06 13:09:48 -0700",
"tests/library_checker_aizu_tests/graphs/offline_incremental_scc.test.cpp": "2026-07-06 13:10:16 -0700",
"tests/library_checker_aizu_tests/graphs/strongly_connected_components_aizu.test.cpp": "2026-07-06 13:10:16 -0700",
"tests/library_checker_aizu_tests/graphs/strongly_connected_components_lib_checker.test.cpp": "2026-07-06 13:10:16 -0700",
"tests/library_checker_aizu_tests/graphs/two_edge_components.test.cpp": "2026-07-06 13:10:16 -0700",
"tests/library_checker_aizu_tests/handmade_tests/count_paths.test.cpp": "2026-07-06 22:18:09 -0700",
"tests/library_checker_aizu_tests/handmade_tests/dsu.test.cpp": "2026-07-06 22:18:09 -0700",
"tests/library_checker_aizu_tests/handmade_tests/edge_cd_small_trees.test.cpp": "2026-07-06 22:18:09 -0700",
"tests/library_checker_aizu_tests/graphs/offline_incremental_scc.test.cpp": "2026-07-06 22:30:55 -0700",
"tests/library_checker_aizu_tests/graphs/strongly_connected_components_aizu.test.cpp": "2026-07-06 22:30:55 -0700",
"tests/library_checker_aizu_tests/graphs/strongly_connected_components_lib_checker.test.cpp": "2026-07-06 22:30:55 -0700",
"tests/library_checker_aizu_tests/graphs/two_edge_components.test.cpp": "2026-07-06 22:30:55 -0700",
"tests/library_checker_aizu_tests/handmade_tests/count_paths.test.cpp": "2026-07-06 22:44:57 -0700",
"tests/library_checker_aizu_tests/handmade_tests/dsu.test.cpp": "2026-07-07 09:17:02 -0700",
"tests/library_checker_aizu_tests/handmade_tests/edge_cd_small_trees.test.cpp": "2026-07-06 22:30:55 -0700",
"tests/library_checker_aizu_tests/handmade_tests/fib_matrix_expo.test.cpp": "2026-07-06 13:10:16 -0700",
"tests/library_checker_aizu_tests/handmade_tests/functional_graph.test.cpp": "2026-07-06 22:43:37 -0700",
"tests/library_checker_aizu_tests/handmade_tests/hilbert_mos.test.cpp": "2026-07-06 13:10:16 -0700",
"tests/library_checker_aizu_tests/handmade_tests/kd_bit.test.cpp": "2026-07-06 13:10:16 -0700",
"tests/library_checker_aizu_tests/handmade_tests/kth_par.test.cpp": "2026-07-06 13:10:16 -0700",
"tests/library_checker_aizu_tests/handmade_tests/kth_par.test.cpp": "2026-07-06 22:44:57 -0700",
"tests/library_checker_aizu_tests/handmade_tests/manacher.test.cpp": "2026-07-06 13:10:16 -0700",
"tests/library_checker_aizu_tests/handmade_tests/merge_st_and_wavelet.test.cpp": "2026-07-06 13:10:16 -0700",
"tests/library_checker_aizu_tests/handmade_tests/mobius.test.cpp": "2026-07-06 13:10:16 -0700",
Expand All @@ -92,7 +92,7 @@
"tests/library_checker_aizu_tests/handmade_tests/sa_find_subarray.test.cpp": "2026-07-06 13:10:16 -0700",
"tests/library_checker_aizu_tests/handmade_tests/seg_tree_find.test.cpp": "2026-07-06 13:10:16 -0700",
"tests/library_checker_aizu_tests/handmade_tests/seg_tree_find_small.test.cpp": "2026-07-06 13:10:16 -0700",
"tests/library_checker_aizu_tests/handmade_tests/seg_tree_midpoint.test.cpp": "2026-07-06 22:18:09 -0700",
"tests/library_checker_aizu_tests/handmade_tests/seg_tree_midpoint.test.cpp": "2026-07-07 09:17:02 -0700",
"tests/library_checker_aizu_tests/handmade_tests/xor_basis_walk.test.cpp": "2026-07-06 13:10:16 -0700",
"tests/library_checker_aizu_tests/loops/chooses.test.cpp": "2026-07-06 13:10:16 -0700",
"tests/library_checker_aizu_tests/loops/quotients.test.cpp": "2026-07-06 13:10:16 -0700",
Expand Down Expand Up @@ -132,23 +132,23 @@
"tests/library_checker_aizu_tests/strings/suffix_array_short.test.cpp": "2026-04-12 06:15:25 -0600",
"tests/library_checker_aizu_tests/strings/trie.test.cpp": "2026-07-06 13:10:16 -0700",
"tests/library_checker_aizu_tests/strings/wildcard_pattern_matching.test.cpp": "2026-07-06 13:10:16 -0700",
"tests/library_checker_aizu_tests/trees/cd_count_paths_per_length.test.cpp": "2026-07-06 22:18:09 -0700",
"tests/library_checker_aizu_tests/trees/edge_cd_contour_range_query.test.cpp": "2026-07-06 22:43:37 -0700",
"tests/library_checker_aizu_tests/trees/edge_cd_contour_range_update.test.cpp": "2026-07-06 22:43:37 -0700",
"tests/library_checker_aizu_tests/trees/edge_cd_count_paths_per_length.test.cpp": "2026-07-06 22:18:09 -0700",
"tests/library_checker_aizu_tests/trees/edge_cd_reroot_dp.test.cpp": "2026-07-06 22:18:09 -0700",
"tests/library_checker_aizu_tests/trees/hld_aizu1.test.cpp": "2026-07-06 13:10:16 -0700",
"tests/library_checker_aizu_tests/trees/hld_aizu2.test.cpp": "2026-07-06 13:10:16 -0700",
"tests/library_checker_aizu_tests/trees/hld_lib_checker_path.test.cpp": "2026-07-06 13:10:16 -0700",
"tests/library_checker_aizu_tests/trees/hld_lib_checker_subtree_edges.test.cpp": "2026-07-06 13:10:16 -0700",
"tests/library_checker_aizu_tests/trees/hld_lib_checker_subtree_nodes.test.cpp": "2026-07-06 13:10:16 -0700",
"tests/library_checker_aizu_tests/trees/kth_path_hagerup.test.cpp": "2026-07-06 13:10:16 -0700",
"tests/library_checker_aizu_tests/trees/kth_path_ladder.test.cpp": "2026-07-06 13:10:16 -0700",
"tests/library_checker_aizu_tests/trees/kth_path_linear.test.cpp": "2026-07-06 13:10:16 -0700",
"tests/library_checker_aizu_tests/trees/kth_path_tree_lift.test.cpp": "2026-07-06 13:10:16 -0700",
"tests/library_checker_aizu_tests/trees/lca_all_methods_aizu.test.cpp": "2026-07-06 13:10:16 -0700",
"tests/library_checker_aizu_tests/trees/lca_all_methods_lib_checker.test.cpp": "2026-07-06 13:10:16 -0700",
"tests/library_checker_aizu_tests/trees/shallowest_aizu_tree_height.test.cpp": "2026-07-06 22:18:09 -0700",
"tests/library_checker_aizu_tests/trees/shallowest_lib_checker_tree_path_composite.test.cpp": "2026-07-06 22:18:09 -0700",
"tests/library_checker_aizu_tests/trees/subtree_isomorphism.test.cpp": "2026-07-06 13:10:16 -0700"
"tests/library_checker_aizu_tests/trees/cd_count_paths_per_length.test.cpp": "2026-07-06 22:30:55 -0700",
"tests/library_checker_aizu_tests/trees/edge_cd_contour_range_query.test.cpp": "2026-07-06 22:30:55 -0700",
"tests/library_checker_aizu_tests/trees/edge_cd_contour_range_update.test.cpp": "2026-07-06 22:30:55 -0700",
"tests/library_checker_aizu_tests/trees/edge_cd_count_paths_per_length.test.cpp": "2026-07-06 22:30:55 -0700",
"tests/library_checker_aizu_tests/trees/edge_cd_reroot_dp.test.cpp": "2026-07-06 22:30:55 -0700",
"tests/library_checker_aizu_tests/trees/hld_aizu1.test.cpp": "2026-07-06 22:44:57 -0700",
"tests/library_checker_aizu_tests/trees/hld_aizu2.test.cpp": "2026-07-06 22:44:57 -0700",
"tests/library_checker_aizu_tests/trees/hld_lib_checker_path.test.cpp": "2026-07-06 22:44:57 -0700",
"tests/library_checker_aizu_tests/trees/hld_lib_checker_subtree_edges.test.cpp": "2026-07-06 22:44:57 -0700",
"tests/library_checker_aizu_tests/trees/hld_lib_checker_subtree_nodes.test.cpp": "2026-07-06 22:44:57 -0700",
"tests/library_checker_aizu_tests/trees/kth_path_hagerup.test.cpp": "2026-07-06 22:44:57 -0700",
"tests/library_checker_aizu_tests/trees/kth_path_ladder.test.cpp": "2026-07-06 22:44:57 -0700",
"tests/library_checker_aizu_tests/trees/kth_path_linear.test.cpp": "2026-07-06 22:44:57 -0700",
"tests/library_checker_aizu_tests/trees/kth_path_tree_lift.test.cpp": "2026-07-06 22:44:57 -0700",
"tests/library_checker_aizu_tests/trees/lca_all_methods_aizu.test.cpp": "2026-07-06 22:44:57 -0700",
"tests/library_checker_aizu_tests/trees/lca_all_methods_lib_checker.test.cpp": "2026-07-06 22:44:57 -0700",
"tests/library_checker_aizu_tests/trees/shallowest_aizu_tree_height.test.cpp": "2026-07-06 22:30:55 -0700",
"tests/library_checker_aizu_tests/trees/shallowest_lib_checker_tree_path_composite.test.cpp": "2026-07-06 22:30:55 -0700",
"tests/library_checker_aizu_tests/trees/subtree_isomorphism.test.cpp": "2026-07-06 22:30:55 -0700"
}
6 changes: 3 additions & 3 deletions library/contest/tester.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# https://github.com/Errichto/youtube/blob/master/testing/s.sh
# bash tester.sh a naive gen

g++ -std=c++20 -g -D_GLIBCXX_DEBUG -fsanitize=address,undefined $1.cpp -o $1.out
g++ -std=c++20 $2.cpp -o $2.out
g++ -std=c++20 $3.cpp -o $3.out
g++ -std=c++23 -g -D_GLIBCXX_DEBUG -fsanitize=address,undefined $1.cpp -o $1.out
g++ -std=c++23 $2.cpp -o $2.out
g++ -std=c++23 $3.cpp -o $3.out

for((i = 1; ; ++i))
do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ vi min_plus(const vi& convex, const vi& arbitrary) {
int n = sz(convex);
int m = sz(arbitrary);
vi res(n + m - 1, INT_MAX);
auto dnc = [&](auto&& dnc, int res_le, int res_ri,
auto dnc = [&](this auto&& dnc, int res_le, int res_ri,
int arb_le, int arb_ri) {
if (res_le >= res_ri) return;
int mid_res = (res_le + res_ri) / 2;
Expand All @@ -22,10 +22,10 @@ vi min_plus(const vi& convex, const vi& arbitrary) {
op_arb = i;
}
}
dnc(dnc, res_le, mid_res, arb_le,
min(arb_ri, op_arb + 1));
dnc(dnc, mid_res + 1, res_ri, op_arb, arb_ri);
dnc(res_le, mid_res, arb_le, min(arb_ri, op_arb + 1));
// NOLINTNEXTLINE(readability-suspicious-call-argument)
dnc(mid_res + 1, res_ri, op_arb, arb_ri);
};
dnc(dnc, 0, n + m - 1, 0, m);
dnc(0, n + m - 1, 0, m);
return res;
}
6 changes: 3 additions & 3 deletions library/graphs/bcc_callback.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@
void bcc(const auto& g, auto f) {
int n = sz(g), q = 0, s = 0;
vi t(n), st(n);
auto dfs = [&](auto&& dfs, int u) -> int {
auto dfs = [&](this auto&& dfs, int u) -> int {
int l = t[u] = ++q;
for (int v : g[u]) {
int siz = s, lu = 0;
l = min(l, t[v] ?: (lu = dfs(dfs, st[s++] = v)));
l = min(l, t[v] ?: (lu = dfs(st[s++] = v)));
if (lu >= t[u]) {
st[s++] = u;
f({siz + all(st) - n + s});
Expand All @@ -57,5 +57,5 @@ void bcc(const auto& g, auto f) {
}
return l;
};
rep(i, 0, n) if (!t[i]) dfs(dfs, i);
rep(i, 0, n) if (!t[i]) dfs(i);
}
6 changes: 3 additions & 3 deletions library/graphs/euler_path.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@
vector<pii> euler_path(auto& g, int m, int s) {
vi vis(m);
vector<pii> path;
auto dfs = [&](auto&& dfs, int u, int eu) -> void {
auto dfs = [&](this auto&& dfs, int u, int eu) -> void {
while (!empty(g[u])) {
auto [v, ev] = g[u].back();
g[u].pop_back();
if (!vis[ev]) vis[ev] = 1, dfs(dfs, v, ev);
if (!vis[ev]) vis[ev] = 1, dfs(v, ev);
}
path.emplace_back(u, eu);
};
dfs(dfs, s, -1);
dfs(s, -1);
ranges::reverse(path);
return path;
}
7 changes: 3 additions & 4 deletions library/graphs/scc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,17 @@
auto scc(const auto& g) {
int n = sz(g), num_sccs = 0, q = 0, s = 0;
vi scc_id(n, -1), tin(n), st(n);
auto dfs = [&](auto&& dfs, int u) -> int {
auto dfs = [&](this auto&& dfs, int u) -> int {
int low = tin[u] = ++q;
st[s++] = u;
for (int v : g[u])
if (scc_id[v] < 0)
low = min(low, tin[v] ?: dfs(dfs, v));
if (scc_id[v] < 0) low = min(low, tin[v] ?: dfs(v));
if (tin[u] == low) {
while (scc_id[u] < 0) scc_id[st[--s]] = num_sccs;
num_sccs++;
}
return low;
};
rep(i, 0, n) if (!tin[i]) dfs(dfs, i);
rep(i, 0, n) if (!tin[i]) dfs(i);
return pair{num_sccs, scc_id};
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ vector<pii> extra_edges(const auto& g, int num_sccs,
zero_in[scc_id[v]] = 0;
}
vector<bool> vis(num_sccs);
auto dfs = [&](auto&& dfs, int u) {
auto dfs = [&](this auto&& dfs, int u) {
if (empty(scc_g[u])) return u;
for (int v : scc_g[u])
if (!vis[v]) {
vis[v] = 1;
int zero_out = dfs(dfs, v);
int zero_out = dfs(v);
if (zero_out != -1) return zero_out;
}
return -1;
Expand All @@ -43,7 +43,7 @@ vector<pii> extra_edges(const auto& g, int num_sccs,
vi in_unused;
rep(i, 0, num_sccs) if (zero_in[i]) {
vis[i] = 1;
int zero_out = dfs(dfs, i);
int zero_out = dfs(i);
if (zero_out != -1) edges.emplace_back(zero_out, i);
else in_unused.push_back(i);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ vi offline_incremental_scc(vector<array<int, 2>> eds,
vi ids(n, -1), joins(m, m), idx(m), vs(n), scc_id;
iota(all(idx), 0);
vector<vi> g;
auto dnc = [&](auto&& dnc, auto el, auto er, int tl,
auto dnc = [&](this auto&& dnc, auto el, auto er, int tl,
int tr) {
g.clear();
int mid = midpoint(tl, tr);
Expand All @@ -42,11 +42,11 @@ vi offline_incremental_scc(vector<array<int, 2>> eds,
auto& [u, v] = eds[*it];
u = scc_id[u], v = scc_id[v];
}
dnc(dnc, el, split, tl, mid);
dnc(dnc, split, er, mid, tr);
dnc(el, split, tl, mid);
dnc(split, er, mid, tr);
};
// uses -1 as the lower bound to correctly handle
// self-edges
dnc(dnc, all(idx), -1, m);
dnc(all(idx), -1, m);
return joins;
}
6 changes: 3 additions & 3 deletions library/graphs/uncommon/bridges.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,19 @@
auto bridges(const auto& g, int m) {
int n = sz(g), num_ccs = 0, q = 0, s = 0;
vi br_id(n, -1), is_br(m), tin(n), st(n);
auto dfs = [&](auto&& dfs, int u, int p) -> int {
auto dfs = [&](this auto&& dfs, int u, int p) -> int {
int low = tin[u] = ++q;
st[s++] = u;
for (auto [v, e] : g[u])
if (e != p && br_id[v] < 0)
low = min(low, tin[v] ?: dfs(dfs, v, e));
low = min(low, tin[v] ?: dfs(v, e));
if (tin[u] == low) {
if (p != -1) is_br[p] = 1;
while (br_id[u] < 0) br_id[st[--s]] = num_ccs;
num_ccs++;
}
return low;
};
rep(i, 0, n) if (!tin[i]) dfs(dfs, i, -1);
rep(i, 0, n) if (!tin[i]) dfs(i, -1);
return tuple{num_ccs, br_id, is_br};
}
6 changes: 3 additions & 3 deletions library/graphs/uncommon/cuts.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@
auto cuts(const auto& g, int m) {
int n = sz(g), num_bccs = 0, q = 0, s = 0;
vi bcc_id(m, -1), is_cut(n), tin(n), st(m);
auto dfs = [&](auto&& dfs, int u, int p) -> int {
auto dfs = [&](this auto&& dfs, int u, int p) -> int {
int low = tin[u] = ++q;
for (auto [v, e] : g[u]) {
assert(u != v);
if (e == p) continue;
if (tin[v] < tin[u]) st[s++] = e;
int lu = -1;
low = min(low, tin[v] ?: (lu = dfs(dfs, v, e)));
low = min(low, tin[v] ?: (lu = dfs(v, e)));
if (lu >= tin[u]) {
is_cut[u] = p >= 0 || tin[u] + 1 < tin[v];
while (bcc_id[e] < 0) bcc_id[st[--s]] = num_bccs;
Expand All @@ -35,6 +35,6 @@ auto cuts(const auto& g, int m) {
}
return low;
};
rep(i, 0, n) if (!tin[i]) dfs(dfs, i, -1);
rep(i, 0, n) if (!tin[i]) dfs(i, -1);
return tuple{num_bccs, bcc_id, is_cut};
}
13 changes: 7 additions & 6 deletions library/trees/centroid_decomp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,20 @@
//! @space O(n)
vi cd(auto& g, auto f) {
vi p(sz(g), -1), s(sz(g), sz(g));
auto ctd = [&](auto&& ctd, int u, int p, int n) -> int {
auto ctd = [&](this auto&& ctd, int u, int p,
int n) -> int {
s[u] = 1;
for (int v : g[u])
if (v != p) {
if (int c = ctd(ctd, v, u, n); c != -1) return c;
if (int c = ctd(v, u, n); c != -1) return c;
s[u] += s[v];
}
return 2 * s[u] >= n ? s[p] = n - s[u], u : -1;
};
auto dfs = [&](auto&& dfs, int u) -> int {
f(u = ctd(ctd, u, u, s[u]));
for (int v : g[u]) erase(g[v], u), p[dfs(dfs, v)] = u;
auto dfs = [&](this auto&& dfs, int u) -> int {
f(u = ctd(u, u, s[u]));
for (int v : g[u]) erase(g[v], u), p[dfs(v)] = u;
return u;
};
return dfs(dfs, 0), p;
return dfs(0), p;
}
Loading