diff --git a/src/lctree.rs b/src/lctree.rs index 4ee3c92..f1b18e2 100644 --- a/src/lctree.rs +++ b/src/lctree.rs @@ -186,8 +186,11 @@ impl LinkCutTree

{ /// assert!(!lctree.linked(alice, clay)); // alice and clay are not connected by a link /// ``` pub fn linked(&mut self, v: usize, w: usize) -> bool { - self.connected(v, w); - self.forest.left_of(w) == Some(v) && self.forest.right_of(v).is_none() + if self.connected(v, w) { + self.forest.left_of(w) == Some(v) && self.forest.right_of(v).is_none() + } else { + false + } } /// Merges two trees into a single tree. @@ -206,7 +209,7 @@ impl LinkCutTree

{ /// assert!(lctree.connected(alice, clay)); /// ``` pub fn link(&mut self, v: usize, w: usize) -> bool { - if !self.connected(v, w) { + if self.connected(v, w) { return false; } // v is the root of its represented tree: diff --git a/src/lib.rs b/src/lib.rs index d6881e3..31b2646 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -9,12 +9,9 @@ //! This crate implements link-cut tree for unrooted trees, which means all of the above operations //! can be performed on any two nodes in the forest. //! -//! # Path aggregation -//! Common path aggregates are provided as follows: -//! - `findmax(v, w)`: returns the maximum value on a path between nodes `v` and `w`. -//! - `findmin(v, w)`: returns the minimum value on a path between nodes `v` and `w`. -//! - `findsum(v, w)`: returns the sum of values on a path between nodes `v` and `w`. -//! A custom aggregation function can also be implemented by using the [Path] trait. +//! # Path operations +//! The most common path aggregates are supported: `FindMax`, `FindMin`, and `FindSum`. +//! A custom path aggregate function can be implemented by using the [Path] trait. //! //! # Tree creation and removal //! Tree nodes are created and removed using the following operations: