Graph Theory37 sections · 1633 units
Open in Course

Problem - Read Statement

(CSES 1666)

Read the problem statement. The graph might have multiple connected components. The job: connect all components with the fewest edges. If the graph already has kk components, you need exactly k1k-1 edges to connect them.

Each edge merges two components. The output is two lines: the number of edges to add, and the list of edges (any valid edges that connect components). You have freedom in choosing which edges to add.