CT38363

Felix's Ledger of ledgers

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

The harbor bell rings at the rookery of Crowhaven; Felix weighs the day's ledgers manifests and starts the calculations. 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 0
Output: 1

Example 2:

Input: 100 1912 64 79 34 84 16 71 56 76 50 81 41 96 24 82 5 96 29 96 24 72 17 83 77 96 14 38 42 63 29 36 51 78 72 75 65 75 37 81 78 99 10 48 17 63 68 81 56 91 32 72 9 21 64 82 26 71 46 57 27 62 42 98 18 84 4 81 12 20 2 65 30 54 17 51 33 85 10 78 64 100 24 97 6 20 16 23 13 55 67 95 43 52 5 25 22 67 10 69 17 28 8 72 25 95 4 83 23 50 21 27 20 97 75 98 17 96 3 33 23 77 11 28 55 86 23 94 15 38 20 80 70 75 56 83 13 52 2 50 27 67 68 91 3 44 58 94 67 82 51 96 44 75 30 53 46 69 16 84 63 74 19 59 53 100 77 88 63 96 52 93 73 78 21 95 37 41 63 78 74 84 51 98 19 99 23 43 29 31 60 79 38 80 10 92 62 90 22 65 41 63 92 94 52 54 3 73 48 56 33 64 12 68 16 20 32 95 38 86 8 12 19 30 2 42 7 62 36 71 32 82 28 54 37 75 45 89 40 93 56 63 26 41 50 85 77 91 16 92 6 15 31 56 48 91 9 55 15 91 61 88 29 47 28 78 10 72 37 44 40…
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.
Felix's Ledger of ledgers - MEDIUM Coding Problem | CodeTikki