File tree Expand file tree Collapse file tree 2 files changed +11
-28
lines changed
tests/library_checker_aizu_tests/trees Expand file tree Collapse file tree 2 files changed +11
-28
lines changed Load Diff This file was deleted.
Original file line number Diff line number Diff line change 11#define PROBLEM \
22 " https://judge.yosupo.jp/problem/jump_on_tree"
33#include " ../template.hpp"
4- #include " ../../../library/trees/linear_kth_path.hpp"
4+ #include " ../../../library/trees/linear_lca.hpp"
5+ #include " ../../../library/trees/ladder_decomposition/linear_kth_par.hpp"
56#include " ../../../library/trees/lca_rmq/lca_rmq.hpp"
67#include " ../compress_tree_asserts.hpp"
78int main () {
@@ -15,12 +16,19 @@ int main() {
1516 adj[u].push_back (v);
1617 adj[v].push_back (u);
1718 }
18- linear_kth_path lin_kth_path (adj);
19+ linear_lca lin_lca (adj);
20+ linear_kth_par lin_kth_par (adj);
1921 LCA lc (adj);
2022 compress_tree_asserts (adj, lc);
2123 while (q--) {
2224 int u, v, k;
2325 cin >> u >> v >> k;
24- cout << lin_kth_path.kth_path (u, v, k) << ' \n ' ;
26+ int lca_d = lin_kth_par.t [lin_lca.lca (u, v)].d ;
27+ int u_lca = lin_kth_par.t [u].d - lca_d;
28+ int v_lca = lin_kth_par.t [v].d - lca_d;
29+ if (k <= u_lca) cout << lin_kth_par.kth_par (u, k) << ' \n ' ;
30+ else if (k <= u_lca + v_lca)
31+ cout << lin_kth_par.kth_par (v, u_lca + v_lca - k) << ' \n ' ;
32+ else cout << -1 << ' \n ' ;
2533 }
2634}
You can’t perform that action at this time.
0 commit comments