CT36992

Jessa's Honeyed marks

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

The council of the jade shrine of Serpentis pays by the answer, and Jessa intends to earn it. First: the full register of marks. 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: 10000 1123 1185 7133 5469 8220 736 9474 1021 9552 3923 9222 4045 6057 7934 9587 3442 6174 2598 4444 470 4921 1003 6160 4809 7284 6498 7419 480 733 4030 6007 77 9287 4121 9353 3277 3853 1980 8347 4801 5955 1307 3853 3244 3501 1740 8995 4354 4638 1934 8799 6227 8807 3247 8358 1834 7075 2232 5761 5913 6441 5060 9175 4992 8711 8715 9860 4973 7173 2259 2517 1186 5513 1065 4507 4853 6327 5530 8713 157 7686 5077 7352 5559 7541 4003 9078 5082 6671 3313 3887 3489 7406 957 4866 3639 7709 6752 8524 1129 8647 1415 3123 3729 8828 4210 9258 268 2803 6621 7880 1759 6978 924 7199 3918 6619 3924 5061 3751 9958 1253 8122 161 5792 3864 8385 4662 7229 7104 7310 530 7585 1053 6706 3694 6040 6622 8932 2395 8322 1001 3199 1046 5986 3072 7423 447 1625 6005 8665 5526 6033 5965 8518 3735 6283 7133 8580 1530 9790 83…
Output: 8876

Example 2:

Input: 10000 2394 6358 8808 363 4968 5375 7383 9326 9892 3007 4906 1411 3461 2296 3144 8321 8788 213 9503 3255 5387 3656 6311 3268 8337 2128 6648 7480 8947 2551 4755 5011 6718 6721 9101 2621 8865 2292 9257 2836 4569 285 2421 4238 4558 2617 8244 1361 5673 3574 9148 3393 5257 6274 7994 957 3418 2646 2807 671 1002 7257 9358 1882 9231 4025 4068 5765 8883 315 8856 442 1341 1820 8290 1709 4111 5186 6365 9034 9335 5502 7098 4134 9621 2075 7501 5939 6215 3428 8386 2478 9551 2834 9839 2751 7749 1234 2214 5144 5796 6208 8147 8074 9281 694 9353 6740 9353 436 9856 452 2231 129 6435 3596 7026 4376 5778 2492 9713 3999 9141 141 3520 591 8107 5945 7828 4100 4161 9207 9755 1657 8699 4614 9510 330 7402 5840 7111 379 3815 1963 5218 983 5493 9246 9310 7183 8982 3437 7997 3829 5753 3208 7826 348 8459 1580 7216 448 20…
Output: 7605

Example 3:

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

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Jessa's Honeyed marks - MEDIUM Coding Problem | CodeTikki