CT36006

Ulrica's Separate Camps Ledger

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

The harbor bell rings at the kelp forests of Tangledeep; Ulrica weighs the day's tunnels manifests and starts the calculations. Task: An undirected graph has n nodes and m edges. Print the number of connected components. Input format: First line: n and m. Next m lines: u v. Output format: Print the component count. Constraints: 1 <= n <= 2009; 0 <= m <= 4018; 1 <= u,v <= n.

Example 1:

Input: 75 2031 31 68 2 71 50 75 11 52 23 37 3 5 54 68 6 72 31 58 44 68 19 28 18 65 4 33 22 43 3 9 23 42 45 73 40 50 23 58 50 54 8 62 33 44 28 72 58 71 68 74 18 27 8 27 53 66 6 20 18 23 33 55 3 32 2 37 55 61 18 37 23 69 6 47 40 75 7 60 23 57 13 20 39 46 6 27 7 72 10 50 44 46 35 43 48 54 27 47 24 39 55 66 36 50 4 54 49 63 13 60 43 54 38 43 8 36 51 58 12 71 31 52 55 63 16 75 15 54 38 55 28 52 6 37 26 60 5 56 19 72 13 15 9 75 42 56 13 27 55 72 3 30 10 11 51 72 12 41 4 40 4 39 4 65 57 69 11 14 25 47 37 59 7 69 31 45 39 74 32 75 20 23 54 65 15 19 28 41 44 54 12 60 34 68 23 72 42 49 2 51 13 72 7 43 62 63 30 69 8 23 11 41 8 43 14 65 9 65 9 41 28 70 11 53 57 68 37 52 7 61 29 32 54 58 38 66 58 65 37 61 13 39 6 21 35 74 13 65 25 59 4 24 7 30 27 68 26 37 16 57 38 50 12 52 56 66 50 53 4 15 33 38 47 74 37 57 1…
Output: 1

Example 2:

Input: 1182 1232 613 1140 164 1155 819 952 171 728 400 926 80 919 530 859 990 1018 310 1161 394 1078 627 1124 27 740 898 956 96 546 403 1182 328 788 789 1081 8 985 491 968 163 956 243 978 381 1077 556 708 315 960 700 853 896 1072 509 1026 509 803 102 706 206 439 178 908 247 471 460 790 599 1055 734 771 524 668 383 708 435 1050 196 323 453 1010 253 350 243 1076 373 977 1025 1085 44 1010 564 1059 25 703 254 735 95 963 303 904 534 1043 315 1171 488 997 54 137 21 101 234 737 576 751 354 1076 216 290 663 895 574 705 665 671 725 1071 526 871 1012 1074 957 1007 691 1143 131 230 293 1131 492 841 163 1128 304 868 237 947 1025 1138 249 589 486 876 232 854 161 916 9 1116 546 684 201 761 394 656 45 928 637 1071 298 483 508 643 324 999 255 1136 514 928 76 425 46 965 870 898 593 1104 705 1027 684 1099 897 945 …
Output: 178

Example 3:

Input: 680 3343 342 361 196 609 36 281 544 622 435 582 20 587 52 249 408 672 163 322 121 656 405 641 196 547 530 649 478 604 460 591 184 536 491 661 62 558 152 417 229 601 93 298 78 178 273 376 209 478 192 463 242 537 94 469 23 340 357 487 510 575 29 304 593 671 149 257 276 650 182 357 148 350 112 535 84 505 270 316 326 379 88 352 454 568 4 440 396 498 149 572 178 228 50 602 432 454 293 613 372 463 185 664 64 83 271 498 25 285 398 514 181 651 539 603 47 305 192 574 107 326 217 331 22 46 337 674 171 537 32 83 162 489 333 603 65 376 100 153 322 476 39 236 83 652 524 571 329 569 295 611 415 531 26 235 286 336 115 645 346 391 132 506 279 306 305 310 24 601 80 399 274 625 471 607 377 486 110 475 65 105 220 228 102 671 452 592 331 656 176 379 165 560 266 423 580 594 501 664 152 367 142 638 67 557 488 4…
Output: 1

Constraints:

1 <= n <= 2009; 0 <= m <= 4018; 1 <= u,v <= n.

Loading...
Test Cases:No test cases
No test cases available.
Ulrica's Separate Camps Ledger - MEDIUM Coding Problem | CodeTikki