Skip to content

Commit 41640d0

Browse files
authored
consistency with partition_point (#56)
Co-authored-by: Luke Videckis <lukevideckis@gmail.com>
1 parent ec94eaa commit 41640d0

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

examples/graphs/hld_path_composite_yosupo.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,11 @@ fn main() {
7272
x: u64
7373
}
7474
let (mut u_anc_val, mut v_anc_val) = (st_forwards.unit, st_backwards.unit);
75-
hld.path(u, v, |range, v_anc| {
76-
if v_anc {
77-
v_anc_val = (st_forwards.op)(&st_forwards.query(range), &v_anc_val);
78-
} else {
75+
hld.path(u, v, |range, u_anc| {
76+
if u_anc {
7977
u_anc_val = (st_forwards.op)(&u_anc_val, &st_backwards.query(range));
78+
} else {
79+
v_anc_val = (st_forwards.op)(&st_forwards.query(range), &v_anc_val);
8080
}
8181
});
8282
let res = (st_forwards.op)(&u_anc_val, &v_anc_val);

src/graphs/hld.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,21 +86,21 @@ impl HLD {
8686
/// - Time: O(log n) calls to `f`
8787
/// - Space: O(1)
8888
pub fn path(&self, mut u: usize, mut v: usize, mut f: impl FnMut(Range<usize>, bool)) {
89-
let mut v_anc = true;
89+
let mut u_anc = false;
9090
loop {
9191
if self.tin[u] > self.tin[v] {
9292
std::mem::swap(&mut u, &mut v);
93-
v_anc = !v_anc;
93+
u_anc = !u_anc;
9494
}
9595
if self.head[u] == self.head[v] {
9696
break;
9797
}
98-
f(self.tin[self.head[v]]..self.tin[v] + 1, v_anc);
98+
f(self.tin[self.head[v]]..self.tin[v] + 1, u_anc);
9999
v = self.p[self.head[v]].unwrap();
100100
}
101101
f(
102102
self.tin[u] + self.vals_edges as usize..self.tin[v] + 1,
103-
v_anc,
103+
u_anc,
104104
);
105105
}
106106

@@ -187,7 +187,7 @@ impl HLD {
187187
pub fn kth_on_path(&self, u: usize, v: usize, k: usize) -> Option<usize> {
188188
let mut dst_side = [0; 2];
189189
self.path(u, v, |range, u_anc| dst_side[u_anc as usize] += range.len());
190-
if k < dst_side[0] {
190+
if k < dst_side[1] {
191191
return self.kth_par(u, k);
192192
}
193193
let dst = dst_side[0] + dst_side[1] - !self.vals_edges as usize;

0 commit comments

Comments
 (0)