Graph Theory37 sections · 1633 units
Open in Course

Problem - Implement Solution

(CSES 1666)

Implement the solution from scratch. Use Union-Find to find components. Connect representatives with a chain of edges. Test the solution on the sample inputs. Make sure it handles already-connected graphs (output 00). Also test completely disconnected graphs where every node is its own component.

If you get stuck, review the algorithm from the previous units. The implementation is simpler than the MST problems because you do not need to track weights.