pub struct LevelAncestor {
parent: Vec<usize>,
depth: Vec<usize>,
start: Vec<usize>,
index: Vec<usize>,
ladder: Vec<usize>,
}Fields§
§parent: Vec<usize>§depth: Vec<usize>§start: Vec<usize>§index: Vec<usize>§ladder: Vec<usize>Implementations§
Source§impl LevelAncestor
impl LevelAncestor
Sourcepub fn la(&self, u: usize, k: usize) -> Option<usize>
pub fn la(&self, u: usize, k: usize) -> Option<usize>
Examples found in repository?
crates/competitive/src/algorithm/doubling.rs (line 338)
335 pub fn kth(&self, u: usize, k: usize) -> (usize, M::T) {
336 let depth = self.depth_to_cycle[u];
337 if k <= depth {
338 let ancestor = self.la.la(u, k).unwrap();
339 let acc = self.acc_to_ancestor(u, ancestor);
340 return (ancestor, acc);
341 }
342 let entry = self.cycle_entry[u];
343 let acc_tree = self.acc_to_ancestor(u, entry);
344 let steps = k - depth;
345 let pos = self.cycle_jump_from(entry, steps);
346 let acc_cycle = self.cycle_acc_from(entry, steps);
347 let acc = M::operate(&acc_tree, &acc_cycle);
348 (pos, acc)
349 }More examples
crates/library_checker/src/tree/jump_on_tree.rs (line 28)
16pub fn jump_on_tree_level_ancestor(reader: impl Read, writer: impl Write) {
17 prepare_io!(reader, writer);
18 sc!(n, q, (g, _): @TreeGraphScanner::<usize>::new(n));
19 let la = g.level_ancestor(0);
20 let lca = g.lca(0);
21 for _ in 0..q {
22 sc!(s, t, i);
23 let l = lca.lca(s, t);
24 let dl = la.depth(l);
25 let ds = la.depth(s) - dl;
26 let dt = la.depth(t) - dl;
27 let ans = if i <= ds {
28 la.la(s, i)
29 } else if i <= ds + dt {
30 la.la(t, ds + dt - i)
31 } else {
32 None
33 };
34 pp!(ans.unwrap_or(!0) as isize);
35 }
36}Sourcepub fn depth(&self, u: usize) -> usize
pub fn depth(&self, u: usize) -> usize
Examples found in repository?
crates/library_checker/src/tree/jump_on_tree.rs (line 24)
16pub fn jump_on_tree_level_ancestor(reader: impl Read, writer: impl Write) {
17 prepare_io!(reader, writer);
18 sc!(n, q, (g, _): @TreeGraphScanner::<usize>::new(n));
19 let la = g.level_ancestor(0);
20 let lca = g.lca(0);
21 for _ in 0..q {
22 sc!(s, t, i);
23 let l = lca.lca(s, t);
24 let dl = la.depth(l);
25 let ds = la.depth(s) - dl;
26 let dt = la.depth(t) - dl;
27 let ans = if i <= ds {
28 la.la(s, i)
29 } else if i <= ds + dt {
30 la.la(t, ds + dt - i)
31 } else {
32 None
33 };
34 pp!(ans.unwrap_or(!0) as isize);
35 }
36}Auto Trait Implementations§
impl Freeze for LevelAncestor
impl RefUnwindSafe for LevelAncestor
impl Send for LevelAncestor
impl Sync for LevelAncestor
impl Unpin for LevelAncestor
impl UnsafeUnpin for LevelAncestor
impl UnwindSafe for LevelAncestor
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more