22 " https://judge.yosupo.jp/problem/jump_on_tree"
33#include " ../template.hpp"
44#include " ../../../library/contest/random.hpp"
5- #include " ../../../library/monotonic_stack/monotonic_stack.hpp"
65#include " ../../../library/trees/tree_lift/tree_lift.hpp"
76#include " ../../../library/trees/lca_rmq/lca_rmq.hpp"
8- #include " ../../../library/trees/linear_lca.hpp"
9- #include " ../../../library/trees/linear_kth_path.hpp"
10- #include " ../compress_tree_asserts.hpp"
117int main () {
128 cin.tie (0 )->sync_with_stdio (0 );
139 int n, q;
@@ -21,42 +17,21 @@ int main() {
2117 }
2218 tree_lift tl (adj);
2319 LCA lc (adj);
24- linear_kth_path lin_kth_path (adj);
25- compress_tree_asserts (adj, lc);
2620 while (q--) {
2721 int u, v, k;
2822 cin >> u >> v >> k;
2923 int dist_in_edges = tl.dist_edges (u, v);
3024 assert (dist_in_edges == lc.dist_edges (u, v));
31- assert (dist_in_edges ==
32- lin_kth_path.lin_lca .dist_edges (u, v));
33- int res = tl.kth_path (u, v, k);
34- assert (res == lin_kth_path.kth_path (u, v, k));
35- cout << res << ' \n ' ;
25+ cout << tl.kth_path (u, v, k) << ' \n ' ;
3626 {
3727 int w = rnd (0 , n - 1 );
3828 assert (lc.on_path (u, v, w) ==
39- (lc.dist_edges (u, w) + lc.dist_edges (w, v) ==
40- lc.dist_edges (u, v)));
29+ (lc.dist_edges (u, w) + lc.dist_edges (w, v) ==
30+ lc.dist_edges (u, v)));
4131 }
4232 if (u != v) {
43- assert (tl.kth_path (u, v, 0 ) == u);
44- assert (lin_kth_path.kth_path (u, v, 0 ) == u);
45- assert (
46- tl.kth_path (u, v, 1 ) == lc.next_on_path (u, v));
47- assert (lin_kth_path.kth_path (u, v, 1 ) ==
48- lc.next_on_path (u, v));
49- assert (tl.kth_path (u, v, dist_in_edges - 1 ) ==
50- lc.next_on_path (v, u));
51- assert (
52- lin_kth_path.kth_path (u, v, dist_in_edges - 1 ) ==
53- lc.next_on_path (v, u));
54- assert (tl.kth_path (u, v, dist_in_edges) == v);
55- assert (
56- lin_kth_path.kth_path (u, v, dist_in_edges) == v);
57- assert (tl.kth_path (u, v, dist_in_edges + 1 ) == -1 );
58- assert (lin_kth_path.kth_path (u, v,
59- dist_in_edges + 1 ) == -1 );
33+ assert (tl.kth_path (u, v, 1 ) == lc.next_on_path (u, v));
34+ assert (tl.kth_path (u, v, dist_in_edges - 1 ) == lc.next_on_path (v, u));
6035 }
6136 }
6237}
0 commit comments