CT51228

Jaya's Separate Camps Ledger

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

The assayer Jaya has been asked to tally the donation drive. On the desk lies a long table of tunnels 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 <= 3391; 0 <= m <= 6782; 1 <= u,v <= n.

Example 1:

Input: 905 5965 245 742 185 751 266 722 587 822 195 581 27 184 415 438 297 315 648 881 573 597 562 778 715 831 616 817 186 838 341 573 19 139 62 657 512 758 249 494 625 682 137 770 525 836 219 822 549 598 268 745 116 407 97 657 658 674 147 339 406 432 191 564 204 818 342 861 431 793 333 801 478 734 92 308 66 518 657 876 6 493 85 783 250 348 652 656 143 610 402 530 131 145 162 837 83 643 317 810 37 215 190 514 18 619 510 759 65 654 196 511 74 577 198 777 352 754 393 759 52 589 101 444 90 318 619 856 71 452 679 748 272 612 371 745 800 815 614 869 409 820 248 393 489 884 88 508 409 634 297 564 555 758 5 703 115 119 149 682 612 841 466 821 506 516 198 799 439 795 350 680 22 338 298 484 147 211 376 591 415 852 650 836 665 854 340 683 194 861 338 790 185 709 756 863 242 287 628 795 768 825 366 552 634 …
Output: 1

Example 2:

Input: 2747 2846 1730 2351 708 1798 379 608 1197 1369 1161 1520 1485 2683 57 2239 900 2165 82 1453 1981 2547 2260 2318 2178 2375 277 2217 441 1185 135 2540 1452 1454 284 2589 558 883 116 2060 397 880 379 1458 951 1299 1922 2312 404 2221 154 732 819 1790 1543 2297 908 1667 629 1178 582 2333 250 1276 1039 2543 163 289 1463 1814 1335 2168 813 2512 360 689 66 975 1178 2131 546 1460 2095 2566 1591 2370 242 817 1215 2704 780 872 232 1280 2134 2688 201 265 653 1521 46 1314 962 1551 315 1174 1671 2416 31 1046 1786 2200 751 2656 521 1698 294 667 759 1104 1291 2329 1149 1550 585 2724 1271 1723 842 2215 1314 2099 397 2450 1581 1927 630 1310 1564 2064 905 1489 709 980 1146 2457 746 2334 114 2709 2110 2550 1473 1701 795 1033 1884 1885 728 2661 1536 2381 341 1452 939 1365 259 398 458 1650 2294 2451 1887 2281 1…
Output: 415

Example 3:

Input: 2068 3155 194 463 703 1447 22 505 286 921 310 1157 383 967 282 2003 1913 2013 166 1841 1313 1788 134 2032 694 1638 362 1175 276 318 366 451 40 77 12 793 878 2045 441 697 533 2065 393 892 1479 1754 247 783 848 1911 1131 1665 1117 1927 440 1468 308 1858 284 1005 999 1726 60 1425 907 1906 186 904 419 855 824 907 1152 1870 220 1989 123 466 120 137 126 1510 43 405 929 1507 113 924 14 1116 252 990 339 1166 246 551 374 983 1043 1054 991 1848 522 1848 58 1953 1318 1537 815 1573 1751 1993 76 1707 373 1224 9 718 1528 1730 421 1510 1338 1698 186 1334 112 1731 610 796 277 1862 597 1450 1450 1885 1071 1884 369 464 898 1935 1164 1359 637 1122 904 1408 54 1581 842 1653 273 630 59 1766 1444 1939 705 1730 1446 1570 923 1567 338 1925 9 94 577 1013 1828 1870 70 815 598 606 641 832 1026 2006 47 104 872 932 11…
Output: 105

Constraints:

1 <= n <= 3391; 0 <= m <= 6782; 1 <= u,v <= n.

Loading...
Test Cases:No test cases
No test cases available.
Jaya's Separate Camps Ledger - MEDIUM Coding Problem | CodeTikki