CT46617

Piper's Ledger of marks

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

In the forest village of Briarthorn, Piper the accountant keeps careful count of the marks. Forecast next month's demand, 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: 10 36 2 4 1 5 6 9 1 8 4 8 6 7 8 9 3 8 5 8 8 10 4 10 5 6 5 9 3 6 7 10 1 7 1 2 3 9 1 6 3 5 9 10 7 8 4 6 3 7 6 8 2 7 7 9 6 10 2 3 5 7 4 9 3 4 1 3 1 4 4 5 1 10
Output: 0

Example 2:

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

Example 3:

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

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Piper's Ledger of marks - MEDIUM Coding Problem | CodeTikki