graph/tree_utils library

Tree utilities (LCA, depth, subtree size) — roadmap #555.

Functions

lowestCommonAncestor(List<int> parent, int u, int v) int
Parent array: entry at index i is the parent of node i; root has -1.
treeDepths(List<int> parent) List<int>
Returns depth of each node (root = 0). parent at index i is the parent of node i.