Skip to content

Commit c139baa

Browse files
committed
switch test
1 parent 8d9023b commit c139baa

File tree

2 files changed

+11
-28
lines changed

2 files changed

+11
-28
lines changed

library/trees/linear_kth_path.hpp

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

tests/library_checker_aizu_tests/trees/kth_path_linear.test.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
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"
78
int 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
}

0 commit comments

Comments
 (0)