|
3 | 3 | #include "../template.hpp" |
4 | 4 | #include "../../../library/contest/random.hpp" |
5 | 5 | #include "../../../library/trees/centroid_decomp_uncommon/count_paths_per_node.hpp" |
6 | | -#include "../../../library/data_structures/dsu/dsu_restorable.hpp" |
7 | | -#include "../../../library/trees/tree_lift/tree_lift.hpp" |
| 6 | +#include "../../../library/trees/lca_rmq/lca_rmq.hpp" |
8 | 7 | #include "../../../library/trees/centroid_decomp_uncommon/count_paths_per_length.hpp" |
9 | 8 | #include "../cd_asserts.hpp" |
10 | | -vector<vector<ll>> naive(const vector<vector<int>>& adj, |
11 | | - dsu_restorable& dsu) { |
12 | | - tree_lift tl(adj); |
| 9 | +vector<vector<ll>> naive(const vector<vi>& adj) { |
| 10 | + LCA lc(adj); |
13 | 11 | int n = sz(adj); |
14 | 12 | vector<vector<ll>> cnts_naive(n + 1, vector<ll>(n, 0)); |
15 | 13 | for (int u = 0; u < n; u++) { |
16 | 14 | for (int v = u; v < n; v++) { |
17 | | - if (dsu.same_set(u, v)) { |
18 | | - int path_length_edges = tl.dist_edges(u, v); |
19 | | - for (int i = 0; i <= path_length_edges; i++) |
20 | | - cnts_naive[path_length_edges] |
21 | | - [tl.kth_path(u, v, i)]++; |
22 | | - } |
| 15 | + int path_length_edges = lc.dist(u, v); |
| 16 | + for (int node = u; node != v; |
| 17 | + node = lc.next_on_path(node, v)) |
| 18 | + cnts_naive[path_length_edges][node]++; |
| 19 | + cnts_naive[path_length_edges][v]++; |
23 | 20 | } |
24 | 21 | } |
25 | 22 | return cnts_naive; |
26 | 23 | } |
27 | 24 | int main() { |
28 | 25 | cin.tie(0)->sync_with_stdio(0); |
29 | 26 | for (int n = 1; n <= 100; n++) { |
30 | | - vector<vector<int>> adj(n); |
31 | | - dsu_restorable dsu(n); |
32 | | - for (int i = 0; i < n - 2; i++) { |
33 | | - int u = rnd<int>(0, n - 1); |
34 | | - int v = rnd<int>(0, n - 1); |
35 | | - if (u == v) continue; |
36 | | - if (dsu.join(u, v)) { |
37 | | - adj[u].push_back(v); |
38 | | - adj[v].push_back(u); |
39 | | - } |
| 27 | + vector<vi> adj(n); |
| 28 | + for (int i = 1; i < n; i++) { |
| 29 | + int par = rnd<int>(0, i - 1); |
| 30 | + adj[par].push_back(i); |
| 31 | + adj[i].push_back(par); |
40 | 32 | } |
41 | 33 | cd_asserts(adj); |
42 | | - vector<vector<ll>> cnts_naive = naive(adj, dsu); |
| 34 | + vector<vector<ll>> cnts_naive = naive(adj); |
43 | 35 | for (int k = 1; k <= n; k++) |
44 | 36 | assert( |
45 | 37 | count_paths_per_node(adj, k) == cnts_naive[k]); |
|
0 commit comments