CP Python LibraryGitHub

Union Find

Data structure for undirected graphs that supports:

__init__

Arguments

Complexities

root

Returns the representative of the connected component containing vertex k. Useful to assign connected components values such as potential.

Arguments

Returns

Complexities

unite

Add an edge spanning between vertices i and j.

Arguments

Returns

Complexities

is_connected

Returns whether vertices i and j are connected.

Arguments

Returns

Complexities

size

Returns the size of the connected component containing vertex k.

Arguments

Returns

Complexities

Code Test