CT38635

Maya and the Separate Camps

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

At the frontier camp of Duskwood, Maya records each routes in a worn leather ledger. The guild wants answers, not guesses. 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 <= 3048; 0 <= m <= 6096; 1 <= u,v <= n.

Example 1:

Input: 1205 739 7 993 60 940 235 807 351 734 660 699 305 826 394 1083 508 1128 343 398 118 759 371 826 266 844 447 869 272 780 220 735 164 1051 263 492 1168 1205 878 1078 569 697 181 1110 222 1188 363 407 25 830 607 638 809 1045 750 920 254 1144 188 732 310 910 14 1103 287 453 536 1147 162 667 612 988 137 665 408 411 79 540 456 658 71 636 220 1175 406 754 348 876 1036 1062 159 881 765 923 74 464 304 1129 701 918 809 995 226 940 292 413 415 855 116 1193 608 680 447 509 301 958 112 1105 991 1155 522 1050 96 541 473 726 166 569 124 1032 173 1052 292 438 337 656 156 441 263 1193 220 748 928 1028 884 980 1034 1076 870 1094 399 1086 485 762 53 737 720 1143 685 1102 8 1143 248 1130 84 130 465 776 475 1016 487 891 68 842 34 1009 149 517 118 266 177 187 209 1186 133 294 26 864 594 610 539 961 193 253 851 …
Output: 469

Example 2:

Input: 1142 1237 156 715 578 950 148 191 483 749 1025 1076 442 953 744 1016 569 1021 514 769 766 1131 355 756 39 858 493 844 585 722 834 886 970 1067 393 610 341 1021 716 1091 625 644 567 806 100 207 898 947 485 915 6 382 759 769 512 645 266 314 603 819 283 1091 124 394 84 286 126 182 190 873 773 1124 847 1134 532 1086 676 1096 337 362 136 1025 710 763 307 751 340 979 757 984 475 1094 123 799 454 790 229 806 491 1100 56 506 220 619 219 417 102 244 1 609 47 1046 535 926 34 954 763 874 439 1081 543 671 929 991 611 912 661 1032 398 465 441 530 223 1041 7 520 588 933 632 808 120 1082 42 733 271 298 360 645 499 697 475 1032 254 1065 121 711 517 1094 521 1020 445 869 137 343 206 376 382 436 89 445 850 1106 418 586 61 973 644 1079 59 286 727 953 41 182 388 741 230 763 739 1018 71 194 1 74 159 1099 563 6…
Output: 162

Example 3:

Input: 781 1342 175 723 350 603 142 345 455 630 380 666 347 406 35 89 82 649 321 467 44 462 53 679 227 531 39 184 32 479 533 703 280 310 361 777 379 740 27 276 276 672 227 494 316 377 157 483 28 670 139 181 45 780 187 485 171 668 25 732 208 662 494 685 302 715 67 622 31 540 7 500 301 443 271 425 56 145 53 776 438 635 79 157 33 774 515 623 350 352 245 770 276 467 205 581 532 648 239 738 283 747 362 750 151 441 60 250 76 390 108 183 179 230 584 677 110 569 226 608 270 509 177 648 147 516 94 552 514 625 542 674 147 387 362 736 390 573 649 664 486 738 605 725 206 499 239 347 149 205 432 588 86 756 287 754 129 311 102 617 2 645 217 748 214 468 186 557 465 717 414 615 124 234 240 453 371 597 418 614 151 155 333 479 146 270 754 767 90 690 353 776 154 207 142 538 301 753 93 180 444 740 402 679 369 631 26…
Output: 26

Constraints:

1 <= n <= 3048; 0 <= m <= 6096; 1 <= u,v <= n.

Loading...
Test Cases:No test cases
No test cases available.