diff --git a/.verify-helper/timestamps.remote.json b/.verify-helper/timestamps.remote.json index eefa99c4..c0443b60 100644 --- a/.verify-helper/timestamps.remote.json +++ b/.verify-helper/timestamps.remote.json @@ -67,7 +67,6 @@ "tests/library_checker_aizu_tests/graphs/strongly_connected_components_aizu.test.cpp": "2025-08-04 17:01:28 -0600", "tests/library_checker_aizu_tests/graphs/strongly_connected_components_lib_checker.test.cpp": "2025-08-04 17:01:28 -0600", "tests/library_checker_aizu_tests/graphs/two_edge_components.test.cpp": "2025-08-04 17:01:28 -0600", -"tests/library_checker_aizu_tests/handmade_tests/count_paths.test.cpp": "2025-08-05 15:52:46 -0600", "tests/library_checker_aizu_tests/handmade_tests/dsu_size.test.cpp": "2024-12-14 19:50:29 -0600", "tests/library_checker_aizu_tests/handmade_tests/edge_cd_small_trees.test.cpp": "2025-04-27 21:47:37 -0600", "tests/library_checker_aizu_tests/handmade_tests/fib_matrix_expo.test.cpp": "2024-12-14 19:50:29 -0600", @@ -126,15 +125,4 @@ "tests/library_checker_aizu_tests/strings/suffix_array_short.test.cpp": "2025-08-05 19:19:23 -0600", "tests/library_checker_aizu_tests/strings/trie.test.cpp": "2024-12-05 10:41:42 -0600", "tests/library_checker_aizu_tests/strings/wildcard_pattern_matching.test.cpp": "2025-08-05 19:19:23 -0600", -"tests/library_checker_aizu_tests/trees/count_paths_per_length.test.cpp": "2025-08-05 15:52:46 -0600", -"tests/library_checker_aizu_tests/trees/edge_cd_contour_range_query.test.cpp": "2025-04-27 21:47:37 -0600", -"tests/library_checker_aizu_tests/trees/edge_cd_contour_range_update.test.cpp": "2025-04-27 21:47:37 -0600", -"tests/library_checker_aizu_tests/trees/edge_cd_count_paths_per_length.test.cpp": "2025-04-27 21:47:37 -0600", -"tests/library_checker_aizu_tests/trees/edge_cd_reroot_dp.test.cpp": "2025-04-27 21:47:37 -0600", -"tests/library_checker_aizu_tests/trees/kth_path_ladder.test.cpp": "2025-08-06 11:58:12 -0600", -"tests/library_checker_aizu_tests/trees/kth_path_linear.test.cpp": "2025-08-06 11:58:12 -0600", -"tests/library_checker_aizu_tests/trees/kth_path_tree_lift.test.cpp": "2025-08-05 15:52:46 -0600", -"tests/library_checker_aizu_tests/trees/lca_all_methods_aizu.test.cpp": "2025-08-06 09:59:41 -0600", -"tests/library_checker_aizu_tests/trees/lca_all_methods_lib_checker.test.cpp": "2025-08-06 09:59:41 -0600", -"tests/library_checker_aizu_tests/trees/subtree_isomorphism.test.cpp": "2025-08-05 18:22:08 -0600" } \ No newline at end of file diff --git a/library/trees/centroid_decomp_uncommon/count_paths_per_length.hpp b/library/trees/centroid_decomp_uncommon/count_paths_per_length.hpp deleted file mode 100644 index dc3e4256..00000000 --- a/library/trees/centroid_decomp_uncommon/count_paths_per_length.hpp +++ /dev/null @@ -1,44 +0,0 @@ -#pragma once -#include "../../../kactl/content/numerical/FastFourierTransform.h" -#include "../centroid_decomp.hpp" -//! @param adj unrooted, connected forest -//! @returns array `num_paths` where `num_paths[i]` = # of -//! paths in tree with `i` edges. `num_paths[1]` = # edges -//! @time O(n log^2 n) -//! @space this function allocates/returns various vectors -//! which are each O(n) -vector count_paths_per_length(const vector& adj) { - vector num_paths(sz(adj)); - centroid(adj, - [&](const vector& cd_adj, int cent, int) { - vector> child_depths; - for (int v : cd_adj[cent]) { - child_depths.emplace_back(1, 0.0); - for (queue q({{v, cent}}); !empty(q);) { - child_depths.back().push_back(sz(q)); - queue new_q; - while (!empty(q)) { - auto [u, p] = q.front(); - q.pop(); - for (int w : cd_adj[u]) { - if (w == p) continue; - new_q.emplace(w, u); - } - } - swap(q, new_q); - } - } - ranges::sort(child_depths, {}, - [&](auto& x) { return sz(x); }); - vector total_depth(1, 1.0); - for (auto& cnt_depth : child_depths) { - auto prod = conv(total_depth, cnt_depth); - rep(i, 1, sz(prod)) num_paths[i] += - llround(prod[i]); - total_depth.resize(sz(cnt_depth)); - rep(i, 1, sz(cnt_depth)) total_depth[i] += - cnt_depth[i]; - } - }); - return num_paths; -} diff --git a/library/trees/extra_members/dist_edges.hpp b/library/trees/extra_members/dist.hpp similarity index 100% rename from library/trees/extra_members/dist_edges.hpp rename to library/trees/extra_members/dist.hpp diff --git a/library/trees/extra_members/in_subtree.hpp b/library/trees/extra_members/in_subtree.hpp index bec278ca..1623e0e0 100644 --- a/library/trees/extra_members/in_subtree.hpp +++ b/library/trees/extra_members/in_subtree.hpp @@ -1,4 +1,4 @@ //! returns 1 if v is in u's subtree bool in_subtree(int u, int v) { - return in[u] <= in[v] && in[v] < in[u] + siz[u]; + return tin[u] <= tin[v] && tin[v] < tin[u] + siz[u]; } diff --git a/library/trees/lca_rmq/next_on_path.hpp b/library/trees/extra_members/next_on_path.hpp similarity index 69% rename from library/trees/lca_rmq/next_on_path.hpp rename to library/trees/extra_members/next_on_path.hpp index 9d307517..1c81a468 100644 --- a/library/trees/lca_rmq/next_on_path.hpp +++ b/library/trees/extra_members/next_on_path.hpp @@ -5,6 +5,7 @@ //! @space O(1) int next_on_path(int u, int v) { assert(u != v); - return in_subtree(u, v) ? rmq.query(in[u] + 1, in[v] + 1) - : p[u]; + return in_subtree(u, v) + ? rmq.query(tin[u] + 1, tin[v] + 1) + : p[u]; } diff --git a/library/trees/extra_members/compress_tree.hpp b/library/trees/extra_members/virtual_tree.hpp similarity index 88% rename from library/trees/extra_members/compress_tree.hpp rename to library/trees/extra_members/virtual_tree.hpp index a956f305..5559fa0f 100644 --- a/library/trees/extra_members/compress_tree.hpp +++ b/library/trees/extra_members/virtual_tree.hpp @@ -1,4 +1,3 @@ -#include "../../monotonic_stack/monotonic_stack.hpp" //! https://github.com/kth-competitive-programming/kactl/blob/main/content/graph/CompressTree.h //! @code //! vector adj(n); @@ -11,7 +10,7 @@ //! @time O(|subset| log |subset|) //! @space O(|subset|) array compress_tree(vi subset) { - auto proj = [&](int v) { return in[v]; }; + auto proj = [&](int v) { return tin[v]; }; ranges::sort(subset, {}, proj); int len = sz(subset); rep(i, 1, len) diff --git a/library/trees/lca_rmq/lca_rmq.hpp b/library/trees/lca_rmq.hpp similarity index 65% rename from library/trees/lca_rmq/lca_rmq.hpp rename to library/trees/lca_rmq.hpp index 38e7150b..def6c02c 100644 --- a/library/trees/lca_rmq/lca_rmq.hpp +++ b/library/trees/lca_rmq.hpp @@ -1,5 +1,6 @@ #pragma once -#include "../../data_structures/rmq.hpp" +#include "../monotonic_stack/monotonic_stack.hpp" +#include "../data_structures/rmq.hpp" //! https://github.com/kth-competitive-programming/kactl/blob/main/content/graph/LCA.h //! @code //! { @@ -14,13 +15,13 @@ // NOLINTNEXTLINE(readability-identifier-naming) struct LCA { int n; - vi in, siz, d, p; + vi tin, siz, d, p; RMQ> rmq = {{}, NULL}; LCA(const auto& adj): - n(sz(adj)), in(n), siz(n, 1), d(n), p(n) { + n(sz(adj)), tin(n), siz(n, 1), d(n), p(n) { vi order; auto dfs = [&](auto&& self, int v) -> void { - in[v] = sz(order), order.push_back(v); + tin[v] = sz(order), order.push_back(v); for (int u : adj[v]) if (u != p[v]) d[u] = d[p[u] = v] + 1, self(self, u), @@ -32,12 +33,12 @@ struct LCA { } int lca(int u, int v) { if (u == v) return u; - auto [x, y] = minmax(in[u], in[v]); + auto [x, y] = minmax(tin[u], tin[v]); return p[rmq.query(x + 1, y + 1)]; } -#include "../extra_members/dist_edges.hpp" -#include "../extra_members/in_subtree.hpp" -#include "../extra_members/on_path.hpp" -#include "next_on_path.hpp" -#include "../extra_members/compress_tree.hpp" +#include "extra_members/dist.hpp" +#include "extra_members/in_subtree.hpp" +#include "extra_members/on_path.hpp" +#include "extra_members/next_on_path.hpp" +#include "extra_members/virtual_tree.hpp" }; diff --git a/library/trees/ladder_decomposition/linear_kth_par.hpp b/library/trees/linear_kth_par.hpp similarity index 100% rename from library/trees/ladder_decomposition/linear_kth_par.hpp rename to library/trees/linear_kth_par.hpp diff --git a/library/trees/linear_lca.hpp b/library/trees/linear_lca.hpp index 5f513b73..01b0c029 100644 --- a/library/trees/linear_lca.hpp +++ b/library/trees/linear_lca.hpp @@ -41,5 +41,5 @@ struct linear_lca { } return d[u] < d[v] ? u : v; } -#include "extra_members/dist_edges.hpp" +#include "extra_members/dist.hpp" }; diff --git a/library/trees/tree_lift/tree_lift.hpp b/library/trees/tree_lift.hpp similarity index 96% rename from library/trees/tree_lift/tree_lift.hpp rename to library/trees/tree_lift.hpp index f3b0ceae..fa0b10d2 100644 --- a/library/trees/tree_lift/tree_lift.hpp +++ b/library/trees/tree_lift.hpp @@ -37,5 +37,5 @@ struct tree_lift { else u = p[u], v = p[v]; return u; } -#include "../extra_members/dist_edges.hpp" +#include "extra_members/dist.hpp" }; diff --git a/library/trees/edge_centroid_decomp_uncommon/contour_range_query.hpp b/library/trees/uncommon/contour_range_query.hpp similarity index 100% rename from library/trees/edge_centroid_decomp_uncommon/contour_range_query.hpp rename to library/trees/uncommon/contour_range_query.hpp diff --git a/library/trees/edge_centroid_decomp_uncommon/contour_range_update.hpp b/library/trees/uncommon/contour_range_update.hpp similarity index 100% rename from library/trees/edge_centroid_decomp_uncommon/contour_range_update.hpp rename to library/trees/uncommon/contour_range_update.hpp diff --git a/library/trees/edge_centroid_decomp_uncommon/count_paths_per_length.hpp b/library/trees/uncommon/count_paths_per_length.hpp similarity index 100% rename from library/trees/edge_centroid_decomp_uncommon/count_paths_per_length.hpp rename to library/trees/uncommon/count_paths_per_length.hpp diff --git a/library/trees/centroid_decomp_uncommon/count_paths_per_node.hpp b/library/trees/uncommon/count_paths_per_node.hpp similarity index 100% rename from library/trees/centroid_decomp_uncommon/count_paths_per_node.hpp rename to library/trees/uncommon/count_paths_per_node.hpp diff --git a/library/trees/ladder_decomposition/ladder_decomposition.hpp b/library/trees/uncommon/ladder_decomposition.hpp similarity index 100% rename from library/trees/ladder_decomposition/ladder_decomposition.hpp rename to library/trees/uncommon/ladder_decomposition.hpp diff --git a/library/trees/subtree_isomorphism.hpp b/library/trees/uncommon/subtree_isomorphism.hpp similarity index 100% rename from library/trees/subtree_isomorphism.hpp rename to library/trees/uncommon/subtree_isomorphism.hpp diff --git a/library/trees/edge_centroid_decomp_uncommon/sum_adjacent.hpp b/library/trees/uncommon/sum_adjacent.hpp similarity index 100% rename from library/trees/edge_centroid_decomp_uncommon/sum_adjacent.hpp rename to library/trees/uncommon/sum_adjacent.hpp diff --git a/tests/.config/.cppcheck_suppression_list b/tests/.config/.cppcheck_suppression_list index 36da6fbe..8ab8df9e 100644 --- a/tests/.config/.cppcheck_suppression_list +++ b/tests/.config/.cppcheck_suppression_list @@ -44,7 +44,6 @@ knownConditionTrueFalse:../library/strings/suffix_array/suffix_array_short.hpp:2 knownConditionTrueFalse:../library/data_structures/dsu/kruskal_tree.hpp:15 constVariable:../kactl/content/numerical/NumberTheoreticTransform.h:30 constVariable:../kactl/content/graph/CompressTree.h:20 -functionStatic:../library/monotonic_stack/monotonic_stack.hpp:10 constVariableReference:../kactl/content/graph/CompressTree.h:20 constVariableReference:../library/flow/min_cost_max_flow.hpp:43 constVariableReference:library_checker_aizu_tests/graphs/connected_components_of_complement_graph.test.cpp:21 diff --git a/tests/library_checker_aizu_tests/handmade_tests/count_paths.test.cpp b/tests/library_checker_aizu_tests/handmade_tests/count_paths.test.cpp index c5176986..73c058b6 100644 --- a/tests/library_checker_aizu_tests/handmade_tests/count_paths.test.cpp +++ b/tests/library_checker_aizu_tests/handmade_tests/count_paths.test.cpp @@ -2,9 +2,9 @@ "https://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_1_A" #include "../template.hpp" #include "../../../library/contest/random.hpp" -#include "../../../library/trees/centroid_decomp_uncommon/count_paths_per_node.hpp" -#include "../../../library/trees/lca_rmq/lca_rmq.hpp" -#include "../../../library/trees/centroid_decomp_uncommon/count_paths_per_length.hpp" +#include "../../../library/trees/uncommon/count_paths_per_node.hpp" +#include "../../../library/trees/lca_rmq.hpp" +#include "../../../library/trees/uncommon/count_paths_per_length.hpp" #include "../cd_asserts.hpp" vector> naive(const vector& adj) { LCA lc(adj); diff --git a/tests/library_checker_aizu_tests/trees/count_paths_per_length.test.cpp b/tests/library_checker_aizu_tests/trees/count_paths_per_length.test.cpp index d1e32efb..bbce584a 100644 --- a/tests/library_checker_aizu_tests/trees/count_paths_per_length.test.cpp +++ b/tests/library_checker_aizu_tests/trees/count_paths_per_length.test.cpp @@ -1,7 +1,7 @@ #define PROBLEM \ "https://judge.yosupo.jp/problem/frequency_table_of_tree_distance" #include "../template.hpp" -#include "../../../library/trees/centroid_decomp_uncommon/count_paths_per_length.hpp" +#include "../../../library/trees/uncommon/count_paths_per_length.hpp" int main() { cin.tie(0)->sync_with_stdio(0); int n; diff --git a/tests/library_checker_aizu_tests/trees/edge_cd_contour_range_query.test.cpp b/tests/library_checker_aizu_tests/trees/edge_cd_contour_range_query.test.cpp index 23b4c604..1e4f02f9 100644 --- a/tests/library_checker_aizu_tests/trees/edge_cd_contour_range_query.test.cpp +++ b/tests/library_checker_aizu_tests/trees/edge_cd_contour_range_query.test.cpp @@ -2,7 +2,7 @@ "https://judge.yosupo.jp/problem/vertex_add_range_contour_sum_on_tree" #include "../template.hpp" #include "../edge_cd_asserts.hpp" -#include "../../../library/trees/edge_centroid_decomp_uncommon/contour_range_query.hpp" +#include "../../../library/trees/uncommon/contour_range_query.hpp" int main() { cin.tie(0)->sync_with_stdio(0); int n, q; diff --git a/tests/library_checker_aizu_tests/trees/edge_cd_contour_range_update.test.cpp b/tests/library_checker_aizu_tests/trees/edge_cd_contour_range_update.test.cpp index 02d20015..da3a0bc2 100644 --- a/tests/library_checker_aizu_tests/trees/edge_cd_contour_range_update.test.cpp +++ b/tests/library_checker_aizu_tests/trees/edge_cd_contour_range_update.test.cpp @@ -2,7 +2,7 @@ "https://judge.yosupo.jp/problem/vertex_get_range_contour_add_on_tree" #include "../template.hpp" #include "../edge_cd_asserts.hpp" -#include "../../../library/trees/edge_centroid_decomp_uncommon/contour_range_update.hpp" +#include "../../../library/trees/uncommon/contour_range_update.hpp" int main() { cin.tie(0)->sync_with_stdio(0); int n, q; diff --git a/tests/library_checker_aizu_tests/trees/edge_cd_count_paths_per_length.test.cpp b/tests/library_checker_aizu_tests/trees/edge_cd_count_paths_per_length.test.cpp index 4ca0428a..6545d13d 100644 --- a/tests/library_checker_aizu_tests/trees/edge_cd_count_paths_per_length.test.cpp +++ b/tests/library_checker_aizu_tests/trees/edge_cd_count_paths_per_length.test.cpp @@ -2,7 +2,7 @@ "https://judge.yosupo.jp/problem/frequency_table_of_tree_distance" #include "../template.hpp" #include "../edge_cd_asserts.hpp" -#include "../../../library/trees/edge_centroid_decomp_uncommon/count_paths_per_length.hpp" +#include "../../../library/trees/uncommon/count_paths_per_length.hpp" int main() { cin.tie(0)->sync_with_stdio(0); int n; diff --git a/tests/library_checker_aizu_tests/trees/kth_path_ladder.test.cpp b/tests/library_checker_aizu_tests/trees/kth_path_ladder.test.cpp index 7df79a15..79c41cb3 100644 --- a/tests/library_checker_aizu_tests/trees/kth_path_ladder.test.cpp +++ b/tests/library_checker_aizu_tests/trees/kth_path_ladder.test.cpp @@ -1,8 +1,8 @@ #define PROBLEM \ "https://judge.yosupo.jp/problem/jump_on_tree" #include "../template.hpp" -#include "../../../library/trees/ladder_decomposition/ladder_decomposition.hpp" -#include "../../../library/trees/ladder_decomposition/linear_kth_par.hpp" +#include "../../../library/trees/uncommon/ladder_decomposition.hpp" +#include "../../../library/trees/linear_kth_par.hpp" int main() { cin.tie(0)->sync_with_stdio(0); int n, q; diff --git a/tests/library_checker_aizu_tests/trees/kth_path_linear.test.cpp b/tests/library_checker_aizu_tests/trees/kth_path_linear.test.cpp index 51aae584..8cf83d40 100644 --- a/tests/library_checker_aizu_tests/trees/kth_path_linear.test.cpp +++ b/tests/library_checker_aizu_tests/trees/kth_path_linear.test.cpp @@ -2,8 +2,8 @@ "https://judge.yosupo.jp/problem/jump_on_tree" #include "../template.hpp" #include "../../../library/trees/linear_lca.hpp" -#include "../../../library/trees/ladder_decomposition/linear_kth_par.hpp" -#include "../../../library/trees/lca_rmq/lca_rmq.hpp" +#include "../../../library/trees/linear_kth_par.hpp" +#include "../../../library/trees/lca_rmq.hpp" #include "../compress_tree_asserts.hpp" int main() { cin.tie(0)->sync_with_stdio(0); diff --git a/tests/library_checker_aizu_tests/trees/kth_path_tree_lift.test.cpp b/tests/library_checker_aizu_tests/trees/kth_path_tree_lift.test.cpp index 35ea2066..098126a4 100644 --- a/tests/library_checker_aizu_tests/trees/kth_path_tree_lift.test.cpp +++ b/tests/library_checker_aizu_tests/trees/kth_path_tree_lift.test.cpp @@ -2,8 +2,8 @@ "https://judge.yosupo.jp/problem/jump_on_tree" #include "../template.hpp" #include "../../../library/contest/random.hpp" -#include "../../../library/trees/tree_lift/tree_lift.hpp" -#include "../../../library/trees/lca_rmq/lca_rmq.hpp" +#include "../../../library/trees/tree_lift.hpp" +#include "../../../library/trees/lca_rmq.hpp" int main() { cin.tie(0)->sync_with_stdio(0); int n, q; diff --git a/tests/library_checker_aizu_tests/trees/lca_all_methods_aizu.test.cpp b/tests/library_checker_aizu_tests/trees/lca_all_methods_aizu.test.cpp index 4a6ac9de..c2011d59 100644 --- a/tests/library_checker_aizu_tests/trees/lca_all_methods_aizu.test.cpp +++ b/tests/library_checker_aizu_tests/trees/lca_all_methods_aizu.test.cpp @@ -1,10 +1,9 @@ #define PROBLEM \ "https://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_5_C" #include "../template.hpp" -#include "../../../library/monotonic_stack/monotonic_stack.hpp" -#include "../../../library/trees/tree_lift/tree_lift.hpp" +#include "../../../library/trees/tree_lift.hpp" #include "../../../library/trees/linear_lca.hpp" -#include "../../../library/trees/lca_rmq/lca_rmq.hpp" +#include "../../../library/trees/lca_rmq.hpp" #include "../compress_tree_asserts.hpp" int main() { cin.tie(0)->sync_with_stdio(0); @@ -25,8 +24,8 @@ int main() { assert(tl.lca(i, i) == i); assert(lc.lca(i, i) == i); assert(lin_lca.lca(i, i) == i); - assert(lc.in[lc.rmq.dp[0][i]] == i && - lc.rmq.dp[0][lc.in[i]] == i); + assert(lc.tin[lc.rmq.dp[0][i]] == i && + lc.rmq.dp[0][lc.tin[i]] == i); } int q; cin >> q; diff --git a/tests/library_checker_aizu_tests/trees/lca_all_methods_lib_checker.test.cpp b/tests/library_checker_aizu_tests/trees/lca_all_methods_lib_checker.test.cpp index 454a8dde..f5eea04d 100644 --- a/tests/library_checker_aizu_tests/trees/lca_all_methods_lib_checker.test.cpp +++ b/tests/library_checker_aizu_tests/trees/lca_all_methods_lib_checker.test.cpp @@ -1,9 +1,8 @@ #define PROBLEM "https://judge.yosupo.jp/problem/lca" #include "../template.hpp" -#include "../../../library/monotonic_stack/monotonic_stack.hpp" -#include "../../../library/trees/tree_lift/tree_lift.hpp" +#include "../../../library/trees/tree_lift.hpp" #include "../../../library/trees/linear_lca.hpp" -#include "../../../library/trees/lca_rmq/lca_rmq.hpp" +#include "../../../library/trees/lca_rmq.hpp" #include "../compress_tree_asserts.hpp" int main() { cin.tie(0)->sync_with_stdio(0); @@ -24,8 +23,8 @@ int main() { assert(lc.lca(i, i) == i); assert(lc.in_subtree(i, i)); assert(lin_lca.lca(i, i) == i); - assert(lc.in[lc.rmq.dp[0][i]] == i && - lc.rmq.dp[0][lc.in[i]] == i); + assert(lc.tin[lc.rmq.dp[0][i]] == i && + lc.rmq.dp[0][lc.tin[i]] == i); } while (q--) { int u, v; diff --git a/tests/library_checker_aizu_tests/trees/subtree_isomorphism.test.cpp b/tests/library_checker_aizu_tests/trees/subtree_isomorphism.test.cpp index de658a2c..28ac422f 100644 --- a/tests/library_checker_aizu_tests/trees/subtree_isomorphism.test.cpp +++ b/tests/library_checker_aizu_tests/trees/subtree_isomorphism.test.cpp @@ -3,7 +3,7 @@ // as std::map insert takes O(n) time in debug mode #undef _GLIBCXX_DEBUG #include "../template.hpp" -#include "../../../library/trees/subtree_isomorphism.hpp" +#include "../../../library/trees/uncommon/subtree_isomorphism.hpp" int main() { cin.tie(0)->sync_with_stdio(0); int n;