Skip to content

Commit 191ff65

Browse files
lrvideckisweb-flow
andauthored
Fixes (#124)
* remove slow test LOL * [auto-verifier] verify commit 3573d11 * trying this * [auto-verifier] verify commit 470a1fd * trying this * [auto-verifier] verify commit e1d1490 * update old var names * [auto-verifier] verify commit 247368a * update --------- Co-authored-by: GitHub <noreply@github.com>
1 parent 46e23c3 commit 191ff65

File tree

6 files changed

+39
-68
lines changed

6 files changed

+39
-68
lines changed

.verify-helper/timestamps.remote.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@
6666
"tests/library_checker_aizu_tests/handmade_tests/count_paths_forest.test.cpp": "2024-12-15 14:34:10 -0600",
6767
"tests/library_checker_aizu_tests/handmade_tests/dsu_size.test.cpp": "2024-12-14 19:50:29 -0600",
6868
"tests/library_checker_aizu_tests/handmade_tests/dynamic_bitset.test.cpp": "2024-11-22 10:47:44 -0600",
69-
"tests/library_checker_aizu_tests/handmade_tests/edge_cd_small_trees.test.cpp": "2024-12-15 14:34:10 -0600",
69+
"tests/library_checker_aizu_tests/handmade_tests/edge_cd_small_trees.test.cpp": "2024-12-15 16:49:53 -0600",
7070
"tests/library_checker_aizu_tests/handmade_tests/fib_matrix_expo.test.cpp": "2024-12-14 19:50:29 -0600",
71-
"tests/library_checker_aizu_tests/handmade_tests/functional_graph.test.cpp": "2024-12-15 14:34:10 -0600",
71+
"tests/library_checker_aizu_tests/handmade_tests/functional_graph.test.cpp": "2024-12-15 16:56:37 -0600",
7272
"tests/library_checker_aizu_tests/handmade_tests/lca_ladder_forest.test.cpp": "2024-12-14 19:50:29 -0600",
7373
"tests/library_checker_aizu_tests/handmade_tests/manacher.test.cpp": "2024-12-14 19:50:29 -0600",
7474
"tests/library_checker_aizu_tests/handmade_tests/merge_st_and_wavelet.test.cpp": "2024-12-14 19:50:29 -0600",
@@ -125,9 +125,10 @@
125125
"tests/library_checker_aizu_tests/strings/trie.test.cpp": "2024-12-05 10:41:42 -0600",
126126
"tests/library_checker_aizu_tests/strings/wildcard_pattern_matching.test.cpp": "2024-12-14 19:50:29 -0600",
127127
"tests/library_checker_aizu_tests/trees/count_paths_per_length.test.cpp": "2024-12-15 14:34:10 -0600",
128-
"tests/library_checker_aizu_tests/trees/edge_cd_contour_range_query.test.cpp": "2024-12-14 18:43:21 -0600",
129-
"tests/library_checker_aizu_tests/trees/edge_cd_contour_range_update.test.cpp": "2024-12-14 18:43:21 -0600",
130-
"tests/library_checker_aizu_tests/trees/edge_cd_count_paths_per_length.test.cpp": "2024-12-14 18:43:21 -0600",
128+
"tests/library_checker_aizu_tests/trees/edge_cd_contour_range_query.test.cpp": "2024-12-15 16:49:53 -0600",
129+
"tests/library_checker_aizu_tests/trees/edge_cd_contour_range_update.test.cpp": "2024-12-15 16:49:53 -0600",
130+
"tests/library_checker_aizu_tests/trees/edge_cd_count_paths_per_length.test.cpp": "2024-12-15 16:49:53 -0600",
131+
"tests/library_checker_aizu_tests/trees/edge_cd_reroot_dp.test.cpp": "2024-12-15 16:49:53 -0600",
131132
"tests/library_checker_aizu_tests/trees/kth_path_ladder.test.cpp": "2024-12-15 14:34:10 -0600",
132133
"tests/library_checker_aizu_tests/trees/kth_path_linear.test.cpp": "2024-12-15 14:34:10 -0600",
133134
"tests/library_checker_aizu_tests/trees/kth_path_tree_lift.test.cpp": "2024-12-15 14:34:10 -0600",

library/graphs/functional_graph_processor.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
//! https://github.com/Aeren1564/Algorithms/blob/master/Algorithm_Implementations_Cpp/Graph_Theory/Special_Graphs/functional_graph_processor.sublime-snippet
33
//! @code
44
//! // 0 <= a[i] < n
5-
//! auto [t2, cycle] = func_graph(a);
6-
//! auto [cyc_id, cyc_pos] = t2[v].root_of;
5+
//! auto [t, cycle] = func_graph(a);
6+
//! auto [cyc_id, cyc_pos] = t[v].root_of;
77
//! int root = cycle[cyc_id][cyc_pos];
88
//! bool is_on_cycle = (v == root);
99
//! @endcode

tests/.config/.cppcheck_suppression_list

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ unusedScopedObject:../library/trees/centroid_decomp_uncommon/count_paths_per_nod
1515
unusedScopedObject:library_checker_aizu_tests/trees/centroid_path_dist.test.cpp:29
1616
unusedScopedObject:../library/trees/edge_centroid_decomp_uncommon/count_paths_per_length.hpp:13
1717
unusedScopedObject:library_checker_aizu_tests/trees/edge_cd_lca.test.cpp:20
18-
unusedScopedObject:library_checker_aizu_tests/trees/edge_cd_reroot_dp.test.cpp:48
18+
unusedScopedObject:library_checker_aizu_tests/trees/edge_cd_reroot_dp.test.cpp:49
1919
unusedScopedObject:library_checker_aizu_tests/trees/cd_jump_on_tree.test.cpp:20
2020
unusedScopedObject:library_checker_aizu_tests/trees/cd_jump_on_tree.test.cpp:58
2121
arrayIndexOutOfBoundsCond:library_checker_aizu_tests/math/linear_prime_sieve.test.cpp:17

tests/library_checker_aizu_tests/edge_cd_asserts.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#pragma once
2-
void edge_cd_asserts(const vector<vector<int>>& adj,
3-
int cent, int split) {
2+
void edge_cd_asserts(const vector<vi>& adj, int cent,
3+
int split) {
44
assert(0 < split && split < sz(adj[cent]));
55
auto dfs = [&](auto&& self, int u, int p) -> int {
66
int siz = 1;

tests/library_checker_aizu_tests/strings/longest_common_substring.test.cpp

Lines changed: 0 additions & 30 deletions
This file was deleted.

tests/library_checker_aizu_tests/trees/edge_cd_reroot_dp.test.cpp

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,34 @@
33
#include "../template.hpp"
44
#include "../edge_cd_asserts.hpp"
55
#include "../../../library/trees/edge_cd.hpp"
6+
#include "../../../library/math/mod_int.hpp"
67
int main() {
78
cin.tie(0)->sync_with_stdio(0);
89
int n;
910
cin >> n;
1011
vector<int> a(n);
11-
vector<int64_t> res(n);
12+
vector<mint> res(n);
1213
for (int i = 0; i < n; i++) {
1314
cin >> a[i];
1415
res[i] = a[i];
1516
}
16-
vector<vector<int>> adj(n);
17-
vector<int> b(n - 1), c(n - 1);
17+
vector<basic_string<int>> adj(n);
18+
vector<mint> b(n - 1), c(n - 1);
1819
vector<pair<int, int>> par(n, {-1, -1});
19-
const int mod = 998'244'353;
20+
vector<vector<int>> base_adj(n);
2021
{
2122
vector<vector<pair<int, int>>> adj_with_id(n);
2223
for (int i = 0; i < n - 1; i++) {
2324
int u, v;
24-
cin >> u >> v >> b[i] >> c[i];
25+
cin >> u >> v >> b[i].x >> c[i].x;
2526
adj[u].push_back(v);
2627
adj[v].push_back(u);
28+
base_adj[u].push_back(v);
29+
base_adj[v].push_back(u);
2730
adj_with_id[u].emplace_back(v, i);
2831
adj_with_id[v].emplace_back(u, i);
29-
res[u] += 1LL * b[i] * a[v] + c[i];
30-
res[u] %= mod;
31-
res[v] += 1LL * b[i] * a[u] + c[i];
32-
res[v] %= mod;
32+
res[u] = res[u] + b[i] * a[v] + c[i];
33+
res[v] = res[v] + b[i] * a[u] + c[i];
3334
}
3435
auto dfs = [&](auto&& self, int u) -> void {
3536
for (auto [v, e_id] : adj_with_id[u])
@@ -44,35 +45,34 @@ int main() {
4445
assert(u_low ^ v_low);
4546
return u_low ? par[u].second : par[v].second;
4647
};
47-
{ edge_cd(adj, edge_cd_asserts); }
48+
{ edge_cd(base_adj, edge_cd_asserts); }
4849
edge_cd(adj,
49-
[&](const vector<vector<int>>& cd_adj, int cent,
50+
[&](const vector<basic_string<int>>& cd_adj, int cent,
5051
int split) -> void {
51-
array<vector<array<int64_t, 3>>, 2> all_backwards;
52-
array<int64_t, 2> sum_forward = {0, 0},
53-
cnt_nodes = {0, 0};
52+
array<vector<array<mint, 3>>, 2> all_backwards;
53+
array<mint, 2> sum_forward = {0, 0};
54+
array<int, 2> cnt_nodes = {0, 0};
5455
auto dfs = [&](auto&& self, int u, int p,
55-
array<int64_t, 2> forwards,
56-
array<int64_t, 2> backwards,
56+
array<mint, 2> forwards,
57+
array<mint, 2> backwards,
5758
int side) -> void {
5859
all_backwards[side].push_back(
5960
{u, backwards[0], backwards[1]});
60-
sum_forward[side] +=
61+
sum_forward[side] = sum_forward[side] +
6162
forwards[0] * a[u] + forwards[1];
62-
sum_forward[side] %= mod;
6363
cnt_nodes[side]++;
6464
for (int v : cd_adj[u]) {
6565
if (v == p) continue;
6666
int e_id = edge_id(u, v);
6767
// f(x) = ax+b
6868
// g(x) = cx+d
6969
// f(g(x)) = a(cx+d)+b = acx+ad+b
70-
array<int64_t, 2> curr_forw = {
71-
forwards[0] * b[e_id] % mod,
72-
(forwards[0] * c[e_id] + forwards[1]) % mod};
73-
array<int64_t, 2> curr_backw = {
74-
b[e_id] * backwards[0] % mod,
75-
(b[e_id] * backwards[1] + c[e_id]) % mod};
70+
array<mint, 2> curr_forw = {
71+
forwards[0] * b[e_id],
72+
forwards[0] * c[e_id] + forwards[1]};
73+
array<mint, 2> curr_backw = {
74+
backwards[0] * b[e_id],
75+
backwards[1] * b[e_id] + c[e_id]};
7676
self(self, v, u, curr_forw, curr_backw, side);
7777
}
7878
};
@@ -84,13 +84,13 @@ int main() {
8484
for (int side = 0; side < 2; side++) {
8585
for (
8686
auto [u, curr_b, curr_c] : all_backwards[side]) {
87-
res[u] += curr_b * sum_forward[!side] +
88-
cnt_nodes[!side] * curr_c;
89-
res[u] %= mod;
87+
res[u.x] = res[u.x] +
88+
curr_b * sum_forward[!side] +
89+
curr_c * cnt_nodes[!side];
9090
}
9191
}
9292
});
93-
for (int i = 0; i < n; i++) cout << res[i] << ' ';
93+
for (int i = 0; i < n; i++) cout << res[i].x << ' ';
9494
cout << '\n';
9595
return 0;
9696
}

0 commit comments

Comments
 (0)