Heavy- Light Decomposition Algorithm

In combinatorial mathematics and theoretical computer science, heavy path decomposition (also named heavy-light decomposition) is a technique for decomposing a rooted tree into a set of paths. In a heavy path decomposition, each non-leaf node chooses one" heavy edge", the edge to the child that has the greatest number of descendants (breaking ties randomly).

Heavy- Light Decomposition source code, pseudocode and analysis