Skip to content

Dynamic connectivity

Dynamic connectivity

Example

Build connections:

union(4, 3)
union(3, 8)
union(6, 5)
union(9, 4)
union(2, 1)

Query connections:

connected(0, 7) // false
connected(8, 9) // true

Build more connections:

union(5, 0)
union(7, 2)
union(6, 1)
union(1, 0)

Query again:

connected(0, 7) // now it's true

–> Source ↗