CP Python LibraryGitHub

Heavy Light Decomposition

Data structure to decompose a tree into at most O(logn)O(\log n) paths. This is useful for answering point/path updates and path queries (most likely in combination with segment tree).

__init__

Arguments

Complexities

where nn represents the number of nodes in the tree.

lca

Finds the lowest common ancestor of two nodes.

Arguments

Returns

Complexities

node_to_order

Returns the decomposition order of nodes so that the nodes on the same path are consecutive.

Returns

edge_to_order

Converts edges to the decomposition order.

Arguments

Returns

path

Returns the decomposition order of the path from u to v.

Arguments

Returns

Complexities

Code Test