CT56988

Theron and the Separate Camps

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Legend says the vault under the kelp forests of Tangledeep opens only for a perfect tally of tunnels. Theron means to find out. 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 <= 3508; 0 <= m <= 7016; 1 <= u,v <= n.

Example 1:

Input: 3352 1969 721 3090 78 775 2392 3288 1491 1987 2082 3275 913 1958 831 2386 1117 1279 1158 2914 420 1747 1466 2754 44 1582 1403 1847 423 3261 821 1870 2107 2924 520 1229 2065 3340 528 2943 489 2364 1458 1928 1677 2818 1653 1878 563 2500 394 2732 1288 3302 46 711 1702 1805 1440 1877 637 1115 1535 2716 451 1842 242 490 1946 2949 398 3006 365 1162 2053 3054 1886 2582 191 420 2207 2560 2687 3068 1483 3291 956 1555 2195 2507 474 1643 60 1108 1730 2581 205 476 1 2050 22 1661 174 285 1605 1698 1 992 761 2082 1812 2142 1824 2524 79 3118 632 774 355 1914 676 1312 2663 2925 1022 2556 86 1335 604 2823 1673 2007 1107 1449 2412 2558 87 1569 144 3160 2700 2917 201 1367 815 904 1045 1100 1269 1681 985 1448 2308 3326 501 2935 379 805 1465 2558 352 2056 158 2005 2431 3162 1444 2493 1465 2606 1953 3066 1220 2…
Output: 1399

Example 2:

Input: 1686 3104 1038 1158 417 1537 157 1293 913 1647 1471 1564 479 788 41 1505 548 830 147 1259 109 1251 612 1111 598 643 83 441 498 1235 905 1006 1029 1201 81 513 40 148 27 1598 645 1101 153 1252 633 1382 925 1323 793 1659 717 762 774 1512 339 866 682 839 1017 1664 1147 1297 292 418 962 1207 26 1392 35 236 882 1363 359 1480 1055 1617 619 755 762 828 459 1421 480 684 313 596 695 1169 312 1657 242 1137 108 680 800 1202 521 1619 147 704 797 1054 1014 1179 1106 1476 236 516 2 559 1028 1232 102 489 185 299 131 370 714 1284 519 588 1103 1410 653 950 191 1636 37 924 951 1400 239 350 913 1480 106 1205 221 574 210 383 1562 1601 1230 1547 423 1184 580 1373 770 1174 747 1589 72 321 91 1670 1304 1485 761 1194 110 606 429 524 483 1385 556 884 1330 1375 173 1387 451 1122 7 1651 166 853 1258 1548 674 1060 185…
Output: 41

Example 3:

Input: 2132 2637 678 841 130 1748 544 2025 208 891 1133 1781 682 704 635 1585 1126 1697 827 1632 1109 1567 874 1088 510 1495 668 830 1909 1995 47 560 417 1453 553 1821 372 583 152 993 686 1317 927 1160 848 1724 1211 1477 1680 1976 573 1661 107 511 526 662 683 827 137 469 260 1602 372 1188 1213 1744 1426 1917 756 1555 1102 1832 168 1972 542 786 1220 2083 735 993 214 739 1099 1449 1455 1968 1605 1615 866 1302 1575 2065 1337 1469 1613 1690 519 785 333 1541 1173 1375 79 1089 586 824 1030 1397 1290 2112 357 907 1137 1163 196 2119 874 1873 80 1376 1449 1918 490 1075 66 1839 756 1939 114 2076 893 1628 528 1139 164 278 682 1491 1477 1694 708 2126 364 1720 589 735 64 555 1617 2102 541 2029 630 1211 180 1333 304 1497 532 911 46 981 20 875 1185 1384 1473 1891 6 913 191 1685 1738 1971 264 596 637 1713 155 63…
Output: 195

Constraints:

1 <= n <= 3508; 0 <= m <= 7016; 1 <= u,v <= n.

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