pub struct LowestCommonAncestor { /* private fields */ }
Expand description
根付き木の LCA です。
Examples
use lowest_common_ancestor::LowestCommonAncestor;
// 0 -- 2 -- 4
// | |
// 1 3
let lca = LowestCommonAncestor::new(5, 0, &[(0, 1), (0, 2), (2, 3), (2, 4)]);
assert_eq!(lca.get(0, 1), 0);
assert_eq!(lca.get(0, 4), 0);
assert_eq!(lca.get(1, 1), 1);
assert_eq!(lca.get(1, 2), 0);
assert_eq!(lca.get(2, 3), 2);
assert_eq!(lca.get(3, 4), 2);