CT36518

Chandler Counts the registers

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

The council of the floating docks of Skyharbor pays by the answer, and Chandler intends to earn it. First: the full register of registers. 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: 4000 2541 93 1822 3132 3969 1485 2036 1360 1630 1984 2755 409 2154 1661 1746 613 1073 1869 3951 2924 3991 1781 2210 955 3020 2153 2377 412 3152 1281 1537 2731 3407 2532 3894 726 1438 2858 3457 1140 1776 1374 2965 2520 3017 120 1418 2030 2149 2146 3439 1653 2957 282 2345 1898 2268 3164 3986 98 2309 128 1526 1498 1968 1252 1997 2943 3490 3764 3776 1215 1723 1826 3799 125 2370 304 2898 122 3830 13 1450 2403 3287 58 276 302 3658 3080 3294 3100 3242 999 3619 469 3126 234 2815 2463 3561 2002 2905 1692 2305 70 1942 1330 2714 213 1886 2084 2883 1349 3827 297 2161 252 1403 2047 3469 296 3727 698 3567 2776 3886 384 2753 674 1607 302 3465 218 1569 3481 3710 2544 2951 936 2872 1030 2996 1132 3989 3621 3677 1482 2090 456 1090 2478 3143 2283 3603 703 1034 1400 2848 1966 3521 2997 3741 774 2384 140 2027 …
Output: 1503

Example 3:

Input: 2 0
Output: 1

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Chandler Counts the registers - MEDIUM Coding Problem | CodeTikki