CT48013

Zara and the Link Budget

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Caravans arrive at the snowberry thicket of Winterholt with crates of registers, and Zara the ledger master must account for every last one. 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 38 4 9 6 7 6 10 5 8 4 6 1 2 2 5 3 7 5 7 4 8 1 4 2 9 5 6 2 7 8 9 7 9 4 10 3 5 2 8 6 9 1 9 2 10 1 7 1 6 5 9 5 10 4 7 1 10 8 10 1 5 3 9 9 10 3 8 3 4 7 8 2 6 3 6 2 4
Output: 0

Example 2:

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

Example 3:

Input: 2 0
Output: 1

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Zara and the Link Budget - MEDIUM Coding Problem | CodeTikki