Skip to main content

build_centroid_tree

Function build_centroid_tree 

Source
pub fn build_centroid_tree(
    adj: &[Vec<usize>],
) -> (Vec<Option<usize>>, Vec<usize>)
Expand description

Build the centroid decomposition of the tree adj.

Returns two vectors of length n:

  • parent[v] — the centroid at the level above v in the decomposition (i.e., the centroid chosen for the component that contained v in the previous recursion step). None for the root of the centroid tree.
  • depth[v] — depth of v in the centroid tree (0 for the root).

§Panics

Panics if adj is empty.