CT52563

Zia's Radiant Ledger

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Before the gates of the crane marshes of Stillwater close for winter, Zia must finish the beacons ledger - one figure at a time. 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 34 1 4 3 8 8 10 1 3 6 8 2 8 3 10 2 9 9 10 3 9 2 5 4 7 4 9 3 6 2 7 2 3 1 5 1 8 6 10 5 7 5 10 3 5 6 9 4 8 7 10 7 9 1 6 4 10 5 8 5 9 1 2 1 10 4 6 8 9
Output: 0

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Zia's Radiant Ledger - MEDIUM Coding Problem | CodeTikki