CT41560

Miller's Separate Camps Ledger

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Before the gates of the coral atoll of Pearldeep close for winter, Miller must finish the roads ledger - one figure at a time. 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 <= 1370; 0 <= m <= 2740; 1 <= u,v <= n.

Example 1:

Input: 952 1495 30 817 549 736 101 918 426 851 226 690 540 780 399 921 121 716 286 910 510 729 147 487 376 730 38 426 377 639 101 351 71 740 614 939 261 675 574 684 294 831 577 717 129 699 518 843 528 558 703 928 479 706 233 292 219 317 110 576 60 812 117 841 557 721 585 817 286 690 339 362 200 755 260 708 77 225 597 694 398 932 419 422 44 847 271 903 146 727 174 735 339 777 315 474 67 573 199 872 874 889 347 399 34 550 296 518 29 237 569 902 589 803 118 529 588 937 238 806 361 552 633 712 83 831 681 717 118 790 88 142 365 631 201 565 381 844 275 719 560 903 145 223 531 574 607 915 489 913 356 758 369 818 328 916 277 614 57 874 830 922 95 307 230 657 298 401 18 494 18 122 494 934 356 369 231 891 687 836 38 283 359 437 415 754 635 721 106 363 157 342 692 878 145 242 169 476 465 592 70 241 270 746 …
Output: 43

Example 2:

Input: 131 1592 116 125 24 50 80 94 70 130 27 115 71 125 50 105 18 67 11 60 27 124 50 89 57 128 73 100 44 60 17 43 47 106 99 117 8 115 8 91 43 84 19 40 113 120 20 61 117 122 77 89 6 114 6 33 61 128 23 40 28 93 20 43 1 81 89 110 14 54 14 80 3 31 1 5 61 122 33 69 74 85 23 107 12 127 86 115 33 127 58 109 32 101 81 96 7 60 58 118 48 96 8 35 8 97 2 105 119 122 22 30 103 117 11 117 7 125 47 83 61 69 37 122 32 77 95 128 24 119 10 36 15 111 4 83 48 55 51 91 41 67 36 87 59 72 51 82 86 89 24 94 58 85 16 97 43 120 7 24 13 52 92 118 7 20 37 67 65 99 54 108 104 123 60 123 7 58 54 84 8 30 60 88 55 93 98 111 36 105 70 116 86 108 58 78 43 81 40 55 4 22 26 106 6 126 72 73 30 67 18 51 60 74 66 115 24 87 34 130 4 75 96 112 30 121 3 89 7 76 86 91 43 79 73 76 8 45 14 93 101 128 4 120 16 108 81 82 81 86 69 97 9 109 10…
Output: 1

Example 3:

Input: 1244 585 325 1095 677 872 234 563 807 1005 131 946 710 823 39 346 181 435 982 1027 1108 1180 1000 1048 936 1027 517 608 224 257 149 1107 583 882 548 1084 840 1169 1069 1070 873 1171 177 1091 69 492 53 727 748 760 480 913 544 957 4 1153 570 873 166 463 45 616 895 903 822 1178 74 114 143 1142 919 1111 401 1030 494 868 1184 1209 653 1187 927 1104 242 285 549 833 480 683 1081 1244 183 704 843 1177 612 1128 383 1122 618 1200 389 1129 773 957 498 991 316 849 635 1083 902 1211 91 917 140 999 945 950 260 425 130 1066 188 224 38 630 275 1085 48 498 45 412 111 640 119 429 466 828 834 908 481 1008 602 802 74 1070 595 1007 751 804 673 1229 181 476 595 833 508 1032 876 1190 67 760 101 578 969 972 561 616 409 1083 126 915 244 963 320 870 668 962 493 555 624 743 589 611 768 1160 379 736 325 717 772 1220 …
Output: 659

Constraints:

1 <= n <= 1370; 0 <= m <= 2740; 1 <= u,v <= n.

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