CT37527

Kabir and the Separate Camps

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Morning light hits the lantern district of Glowfen as Kabir unrolls the day's manifest of canals. The tally will decide the next shipment. 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 <= 2821; 0 <= m <= 5642; 1 <= u,v <= n.

Example 1:

Input: 1050 3211 342 391 228 353 241 784 88 1017 44 330 527 816 918 996 489 737 410 545 273 862 77 393 955 999 205 325 920 1034 554 823 242 510 242 943 568 697 233 303 297 824 475 477 421 677 249 770 175 434 145 149 443 957 66 688 289 708 98 529 2 295 636 1019 63 94 41 768 128 839 293 806 317 959 768 843 171 963 300 926 8 129 46 463 828 1023 147 696 286 589 28 37 688 1031 349 555 956 992 100 1026 60 632 791 871 839 870 374 664 42 251 317 619 543 681 3 392 121 461 231 875 193 628 683 714 339 638 37 879 47 361 2 536 534 995 693 773 380 730 694 976 765 865 57 364 434 884 139 222 673 964 197 528 256 597 726 941 192 737 550 627 647 958 830 1035 82 631 132 602 54 259 3 141 118 760 222 788 831 930 525 786 306 633 956 989 171 1039 375 849 157 158 485 706 793 953 670 824 511 549 290 571 42 720 430 570 702…
Output: 3

Example 2:

Input: 950 1919 393 849 231 236 292 779 15 368 15 839 202 898 309 730 311 578 516 602 830 888 392 608 48 718 854 869 37 427 303 480 153 665 158 872 106 451 776 845 652 654 593 782 168 917 132 517 295 506 410 880 126 350 273 323 612 820 22 129 899 933 139 272 316 774 384 537 444 889 231 294 208 938 6 760 44 304 76 397 284 818 221 536 377 813 250 423 19 834 272 672 747 929 110 123 101 929 284 646 444 603 390 469 83 105 296 918 705 740 512 639 232 682 194 413 268 565 52 216 215 496 263 570 70 455 3 305 557 630 509 856 637 903 682 799 460 705 468 908 524 629 529 663 417 536 522 709 318 919 15 483 41 371 422 919 262 908 78 469 250 922 477 519 636 646 213 379 454 926 227 916 520 878 82 754 244 693 314 651 110 264 290 732 774 910 67 341 473 874 131 491 166 934 102 497 317 738 164 739 287 454 197 721 441…
Output: 23

Example 3:

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

Constraints:

1 <= n <= 2821; 0 <= m <= 5642; 1 <= u,v <= n.

Loading...
Test Cases:No test cases
No test cases available.
Kabir and the Separate Camps - MEDIUM Coding Problem | CodeTikki