CT42066

Gilded ledgers Link Budget

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

In the cotton rows of Whitewick, Chetan the cartographer keeps careful count of the ledgers. balance the workshop's books, every figure matters. 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: 2 1 1 2
Output: 0

Example 2:

Input: 2 0
Output: 1

Example 3:

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

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Gilded ledgers Link Budget - MEDIUM Coding Problem | CodeTikki