Wires to Add — Solution & Editorial
Adding one edge can merge at most two components, and connecting component representatives in a chain achieves it: answer = C − 1.
Complexity: O(N + M)
Adding one edge can merge at most two components, and connecting component representatives in a chain achieves it: answer = C − 1.
Complexity: O(N + M)