CT56284

The routes Separate Camps Puzzle

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

The archivist Orin has been asked to settle a dispute between crews. On the desk lies a long table of routes readings. 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 <= 3219; 0 <= m <= 6438; 1 <= u,v <= n.

Example 1:

Input: 1942 5423 1497 1547 358 1261 283 888 978 1411 606 798 1147 1794 997 1151 235 802 924 1291 1429 1698 717 1293 342 1932 1563 1874 739 1378 1386 1606 197 1921 837 1442 232 685 61 1125 293 720 267 386 42 829 669 1328 783 1609 277 1467 1429 1872 716 1209 632 709 818 1362 140 970 1483 1828 898 1335 486 1528 1084 1289 371 1878 1611 1853 140 1274 210 638 239 746 354 1475 1265 1766 1620 1866 44 504 1254 1898 257 1257 748 1335 23 103 1139 1392 188 883 292 1586 385 1166 476 1109 830 831 496 522 572 1879 1108 1243 780 1678 107 1722 142 1109 824 1230 88 105 705 1910 1503 1879 727 1070 198 1192 1139 1674 120 958 1154 1200 117 708 702 941 981 1324 772 1014 162 543 34 1939 299 1499 832 853 1033 1503 660 1406 357 412 939 1622 234 1558 281 1355 759 1627 18 686 805 1252 79 288 316 966 340 1545 512 1108 1139 …
Output: 11

Example 2:

Input: 847 3912 36 763 423 427 74 504 259 839 167 751 484 539 46 791 63 278 460 768 74 115 36 600 450 670 17 188 170 772 506 708 17 601 55 838 151 384 398 748 627 661 14 76 156 163 302 580 90 284 145 489 387 753 477 662 258 779 524 811 606 827 216 464 140 491 438 831 550 600 21 812 28 292 723 791 57 804 280 649 296 337 644 750 167 549 196 703 109 547 36 522 339 653 311 764 493 687 355 802 23 601 648 737 41 504 232 534 327 778 33 632 194 576 740 819 726 759 371 516 662 685 446 706 111 246 303 747 22 403 374 517 723 755 298 310 28 832 268 730 115 434 686 690 180 844 703 707 551 614 812 836 518 782 184 352 391 718 179 360 356 399 642 726 427 643 534 764 216 529 204 648 325 351 611 840 411 840 192 314 292 602 51 263 8 36 566 636 307 396 101 632 233 508 366 457 60 502 76 387 47 728 140 543 7 385 136 4…
Output: 1

Example 3:

Input: 1147 3822 427 1068 27 811 109 508 242 546 281 605 122 831 241 654 442 464 525 723 832 1065 101 278 102 131 277 616 160 326 224 869 606 851 76 245 1045 1108 348 514 170 190 159 390 951 959 442 750 548 626 805 914 249 957 790 1139 211 706 119 560 706 1087 55 1053 532 1110 346 439 463 966 122 1101 107 348 659 784 6 364 814 839 333 1095 259 1128 131 968 110 879 333 578 168 752 985 1067 182 228 346 968 862 905 174 737 354 1139 46 1066 356 734 259 633 191 671 426 847 1000 1018 42 640 861 1034 311 495 381 934 568 1023 951 975 802 1101 18 1094 22 952 24 202 253 789 586 657 739 1032 698 852 413 607 258 595 912 984 746 871 615 918 157 989 578 1089 152 910 266 1128 682 1090 674 1093 95 855 694 1057 82 253 85 548 627 1120 459 668 179 245 923 1027 829 1105 473 707 771 824 659 841 497 630 124 394 182 10…
Output: 4

Constraints:

1 <= n <= 3219; 0 <= m <= 6438; 1 <= u,v <= n.

Loading...
Test Cases:No test cases
No test cases available.
The routes Separate Camps Puzzle - MEDIUM Coding Problem | CodeTikki