CT41240

Diya and the Separate Camps

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

In the seal rocks of Barking Cove, Diya the reckoner keeps careful count of the routes. plan the harvest festival, every figure matters. 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 <= 3523; 0 <= m <= 7046; 1 <= u,v <= n.

Example 1:

Input: 2210 4819 333 942 650 2206 990 1293 206 903 452 494 381 1501 1258 1321 690 754 219 1683 322 1036 579 697 296 594 705 1225 259 2080 1100 1214 618 643 623 861 102 2160 1223 1788 1557 1909 167 1708 794 1854 506 1642 1297 2188 613 1364 124 363 1355 1539 274 682 853 2186 615 1831 834 1457 1892 2113 712 1529 1425 1602 547 1583 300 1826 53 873 1836 2094 1338 1949 660 721 990 2101 1006 1636 1892 2147 386 1096 1420 1912 557 2053 417 1389 1211 1919 100 1695 298 1715 1679 1896 936 2175 250 712 834 1899 1003 1800 414 1177 598 1778 532 577 176 1522 934 1702 817 1337 401 1430 850 1734 603 949 768 2205 822 852 610 1312 977 1781 926 1492 1080 2174 1402 2072 744 1614 700 921 583 686 348 1475 919 1764 412 1069 861 1788 1217 1892 792 1563 1265 1965 300 1493 565 1948 817 999 587 2099 809 1336 63 473 506 770 1…
Output: 19

Example 2:

Input: 183 436 138 155 73 149 129 136 119 122 146 178 20 78 62 176 27 113 43 154 138 166 42 133 102 113 28 46 68 119 29 110 41 60 96 160 111 169 75 77 10 41 36 120 39 134 71 171 47 125 154 159 52 139 89 136 1 101 91 119 104 169 52 120 141 177 41 133 42 163 58 156 15 95 60 70 96 101 63 65 66 87 62 122 9 33 156 179 3 42 125 159 26 136 48 180 1 63 17 152 153 163 10 62 102 174 19 88 40 47 4 10 6 100 13 141 35 122 100 121 47 147 150 156 61 158 4 139 153 174 82 122 50 78 6 83 73 104 169 173 88 89 116 131 132 172 140 168 71 133 97 139 60 148 4 108 133 161 85 158 159 180 17 18 48 159 90 132 121 122 134 153 71 119 6 77 62 72 2 145 59 82 86 87 81 148 53 115 111 156 22 51 113 115 82 114 91 183 157 172 147 171 23 82 22 169 49 98 74 102 124 157 72 155 3 21 77 143 78 153 41 132 98 146 36 92 4 22 114 183 15 59 …
Output: 3

Example 3:

Input: 2975 1458 757 1181 443 2188 703 2305 2409 2703 1078 2428 2301 2919 508 1634 1086 2081 532 1183 1657 2547 785 860 446 2477 1049 1142 1635 2065 24 1872 431 1910 725 2973 1906 2572 1342 2819 201 928 119 897 302 1893 301 549 190 270 2474 2737 1388 2852 595 2366 1393 2153 1240 2126 479 2734 534 2266 1244 2080 299 1795 2411 2934 1300 1528 145 1994 1069 2054 48 2841 1905 2312 639 1209 123 1153 2189 2456 974 2966 1636 2210 474 1416 23 2456 98 1570 610 1686 104 2553 720 1295 675 1021 938 2508 1988 2492 91 1522 752 2739 504 2257 260 2322 725 1868 861 1472 1774 2097 2181 2776 2362 2653 823 1758 77 1591 301 685 325 1540 90 2312 695 1165 1407 2030 382 1225 2376 2693 1664 2755 2063 2687 2733 2898 160 2594 471 955 444 1855 1347 2418 891 913 211 2537 1896 2812 833 1486 2409 2446 388 696 1705 2612 824 1122…
Output: 1517

Constraints:

1 <= n <= 3523; 0 <= m <= 7046; 1 <= u,v <= n.

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