CP Python LibraryGitHub

Link Cut Tree

Data structure that extends lazy segment tree for dynamic trees with vertices of monoid (M,,e)(M, \cdot, e) to support:

__init__

Arguments

Complexities

where nn represents the length of A.

evert

Make a given node v the root of the tree including v.

Arguments

Complexities

lca

Returns the lowest common ancestor of two given nodes u and v.

Note: Ancestors are dependant on the root, so you must explicitly call evert before using this method.

Arguments

Returns

Complexities

link

Given two nodes u and v, make u's parent v.

Arguments

Complexities

cut

Given a node u, remove the edge between u and its parent.

Arguments

Complexities

is_connected

Returns whether vertices u and v are connected.

Arguments

Returns

Complexities

depth

Returns the depth of a given node v.

Arguments

Returns

Complexities

act

Applies a function fEnd(M)f \in \text{End}(M) to all vertices on the path between two given nodes u and v.

Arguments

Complexities

prod

Calculates the product of all vertices on the path between two given nodes u and v.

Arguments

Returns

Complexities

Code Test