CT54324

Envoy's signals Reckoning

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Envoy runs the ropewalk at the shale slopes of Greystone. Today the books show a list of signals, and the numbers must be worked out before sundown. 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 21 1 2 3 6 4 7 4 8 3 10 1 7 1 4 2 10 4 10 2 7 6 10 2 5 8 10 3 7 2 4 1 10 3 8 2 6 2 9 5 8 4 9
Output: 0

Example 2:

Input: 100 3295 19 86 42 68 27 66 61 82 35 56 24 50 18 62 2 71 54 89 23 70 39 81 21 51 38 71 23 51 72 84 6 16 9 12 40 100 77 98 51 68 44 77 5 54 29 83 95 100 11 32 60 78 45 68 9 100 27 98 36 57 4 16 9 46 21 47 5 49 4 80 7 14 14 19 2 56 47 66 10 97 16 17 32 94 44 87 19 77 4 76 15 78 11 62 2 60 32 71 31 59 14 99 59 82 19 82 23 88 51 75 10 18 4 59 88 94 55 60 64 99 57 93 72 75 41 77 1 86 12 35 58 63 10 84 28 31 2 53 76 95 7 23 21 40 44 49 3 51 29 72 12 81 18 27 59 65 10 43 64 96 79 97 15 95 49 52 24 47 9 87 61 78 23 95 47 55 26 40 33 49 48 51 72 77 41 64 1 49 27 37 72 82 9 56 42 53 15 63 15 85 63 69 37 70 43 55 47 73 11 41 26 87 20 82 74 88 21 52 29 39 87 90 16 28 66 87 14 54 76 97 48 87 31 76 66 82 51 58 46 90 62 90 2 49 36 54 20 50 10 51 31 41 32 68 65 100 48 92 41 94 21 57 43 52 66 94 26 90 21 93…
Output: 0

Example 3:

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

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.