CT35025

Brevin and the Separate Camps

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Brevin inherited the boathouse at the mountain city of Highreach along with its curious bookkeeping system for canals. Time to make sense of it. 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 <= 2930; 0 <= m <= 5860; 1 <= u,v <= n.

Example 1:

Input: 2829 1197 996 1929 2202 2322 401 1056 236 1183 304 512 876 2183 1038 1443 1198 2248 506 2621 626 1121 403 576 268 640 1922 2536 1843 2239 884 1994 579 2510 421 2795 616 2183 300 2778 1186 1830 1174 2391 1312 2024 2177 2581 482 1305 202 1589 1075 1210 86 222 1120 2477 406 2185 2531 2691 369 1678 966 2503 760 2341 14 1992 1852 1909 1087 1707 1744 2685 1386 1874 2070 2454 1968 2044 482 1909 871 2400 2492 2680 1970 1975 2255 2809 566 1934 968 2544 853 2445 527 1847 2084 2541 1537 2104 1677 2716 1116 1988 1314 2073 305 2474 2402 2524 1595 2032 780 1650 419 1076 389 952 1558 2240 2 2726 2420 2762 1994 2321 333 2771 996 1863 866 2658 55 370 1371 1829 889 1623 1590 2490 2544 2754 1541 2128 494 2144 925 2462 268 2703 1054 2113 1327 2396 628 2411 1513 2790 637 1665 939 1476 759 773 2375 2697 305 200…
Output: 1634

Example 2:

Input: 2360 1467 690 1702 787 865 362 1951 877 2200 894 2270 1567 2284 224 2158 2163 2231 4 2117 225 2322 866 1138 499 1111 883 2025 520 1431 117 1244 358 1279 2 311 1196 2269 479 2220 448 1645 87 189 473 1968 129 2211 1502 1562 408 841 756 812 24 720 495 2091 44 383 91 247 460 971 460 1400 231 1227 341 1060 582 1922 109 1635 343 657 1429 1518 559 731 177 245 611 2268 857 2319 745 2263 1612 1750 555 1406 691 2351 493 1570 589 2187 624 2130 1267 1921 1934 2142 180 2287 100 1260 1783 1831 115 1890 1216 1923 909 2051 1359 2238 295 1847 1393 1854 761 1927 1948 1993 755 1867 2123 2340 1060 2332 735 2323 1254 2013 8 750 30 1143 1166 1319 840 1818 2120 2273 229 961 1218 1517 1197 1745 892 1376 1474 1660 1656 1661 170 187 2015 2246 1212 1832 740 1475 817 995 493 1233 860 1087 281 1618 2196 2248 245 1701 …
Output: 908

Example 3:

Input: 1113 2025 102 876 325 684 297 570 511 817 861 901 276 738 206 622 789 936 628 669 67 745 891 993 126 1014 118 904 157 736 583 865 481 628 284 1023 456 851 191 759 117 275 294 857 263 712 556 912 10 1102 315 570 20 73 347 520 531 606 772 808 135 412 649 708 27 343 254 1086 786 838 273 358 324 381 272 639 2 83 273 297 710 924 59 317 39 598 393 954 473 717 67 1096 540 859 115 351 209 282 154 654 292 321 444 786 148 449 489 1074 963 1008 573 777 207 764 54 640 312 870 12 39 889 1040 339 969 403 1037 684 965 123 839 115 123 285 662 37 421 246 774 704 1037 443 768 378 944 307 318 351 1062 816 874 131 775 629 866 424 1060 281 1008 645 741 1009 1057 321 439 364 922 243 555 218 342 40 175 1045 1058 9 307 856 965 711 919 639 994 511 574 427 532 487 881 199 1084 154 656 206 611 347 1085 1033 1062 319…
Output: 26

Constraints:

1 <= n <= 2930; 0 <= m <= 5860; 1 <= u,v <= n.

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