CT45144

Sona's beacons Link Budget

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Sona runs the mint at the ivy courts of Vineward. Today the books show a list of beacons, and the numbers must be worked out before sundown. Task: n isolated nodes are joined by m edges (some may be redundant). Print the minimum number of additional edges needed to make the graph connected. Input format: First line: n and m. Next m lines: u v. Output format: Print the number of extra edges needed. Constraints: 1 <= n <= 4000; 0 <= m <= 4000.

Example 1:

Input: 10 27 6 10 7 10 4 7 7 9 2 7 2 5 1 4 3 7 3 10 8 10 2 10 1 9 2 9 4 6 2 8 1 6 1 7 2 3 5 6 8 9 4 10 6 7 2 6 1 5 1 8 5 7 5 9
Output: 0

Example 2:

Input: 10 0
Output: 9

Example 3:

Input: 10 3 9 10 1 5 2 8
Output: 6

Constraints:

1 <= n <= 4000; 0 <= m <= 4000.

Loading...
Test Cases:No test cases
No test cases available.
Sona's beacons Link Budget - MEDIUM Coding Problem | CodeTikki