Safe Haskell | None |
---|---|
Language | Haskell2010 |
Heavy-light decomposition
Decomposition of a tree of size n into multiple paths, such that there are O(log n) paths between any pair of vertices.
HLD is useful for problems that have queries or updates on the path between two vertices.
This implementation maps each node to an integer position in [1..n] such that nodes in a path have consecutive positions. A path between two vertices decomposes into O(log n) ranges of consecutive integers, possibly simplifying the problem.
Sources:
Documentation
pathHLD :: HLD -> Vertex -> Vertex -> [(Int, Int)] Source #
A list of position ranges which make up the path from u to v. O(log n).
edgePathHLD :: HLD -> Vertex -> Vertex -> [(Int, Int)] Source #
pathsHLD but excludes the LCA. Useful when working with edges, each edge can be mapped to the node it leads down into. O(log n).