CT53310

The Separate Camps of the Bright canals

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Deep in the river town of Willowford, Bhanu studies rows of canals entries. One clean number will settle the guild's oldest argument. 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 <= 3259; 0 <= m <= 6518; 1 <= u,v <= n.

Example 1:

Input: 2964 5036 745 1795 1224 2038 1744 2181 69 2621 998 1605 1076 2784 1963 2187 320 2463 1070 1166 1596 2106 2590 2844 1158 2256 809 2907 271 2772 2468 2640 1057 2542 86 1821 100 1274 1781 2179 216 2392 686 2197 995 2494 1287 2796 575 1437 2033 2895 1718 2599 2194 2493 340 2069 711 1945 741 2809 41 2818 586 1685 1464 2136 493 2617 853 2562 367 428 1068 2842 953 1435 2362 2580 724 2659 1415 2074 1048 2433 2285 2920 771 2511 1619 2516 539 1019 182 2586 759 1555 11 2097 2252 2774 89 2386 1007 2719 1718 1970 740 1461 1355 2590 1742 2009 781 1972 1699 1927 549 872 224 2605 70 813 1707 2581 522 1673 45 1965 1077 1260 763 1130 99 2354 135 1576 2223 2418 102 765 1239 1696 75 754 688 1247 2173 2579 2270 2802 1769 2243 350 2653 2123 2421 1154 1164 1442 2238 1084 1594 1117 1881 2520 2614 768 1182 1131 23…
Output: 93

Example 2:

Input: 2760 5905 1675 2485 2146 2316 119 502 2154 2587 549 2680 1231 1872 586 1079 152 2110 1202 2026 779 1617 324 2331 1650 1776 642 2688 1384 1453 1394 2401 370 992 160 2351 2037 2449 1595 2190 1336 2021 21 247 2350 2712 983 1281 562 2655 1753 2540 1276 2261 703 1829 1206 1343 2619 2626 240 914 971 1966 719 2375 202 1052 1453 1624 1309 2757 2345 2666 649 1028 421 823 626 1731 155 1752 195 2724 555 1346 1273 2111 875 1268 2348 2392 1397 2531 530 2385 892 1754 467 593 1195 2126 1152 2422 1101 2450 1214 2061 598 2754 215 1429 69 1509 211 1014 1593 2119 372 826 2245 2259 1498 1549 578 2332 1523 2493 1210 1327 770 1514 1633 2225 599 1980 652 2143 804 2333 2243 2551 1169 1945 795 911 62 2732 491 2398 717 1854 1376 1923 1793 1905 256 1213 805 1322 97 2226 467 1418 258 1075 80 1839 956 1127 2242 2473 4…
Output: 28

Example 3:

Input: 818 3531 747 796 350 781 413 676 475 521 146 169 577 607 35 247 178 506 145 737 546 683 223 613 9 649 47 537 677 785 195 360 291 770 3 424 246 659 20 251 216 367 596 760 220 665 556 632 27 176 463 596 376 531 338 397 72 77 164 653 29 555 69 323 219 351 317 637 65 159 82 720 41 128 52 284 509 530 32 660 122 476 123 803 48 562 322 711 459 652 274 758 211 286 377 484 13 603 219 333 121 583 60 679 204 337 373 681 12 344 42 234 114 362 12 220 411 543 761 798 221 484 189 685 353 420 530 667 658 771 115 186 372 397 273 309 174 631 111 768 111 363 84 417 367 498 95 592 133 579 185 340 289 626 592 682 262 808 7 674 438 784 307 596 34 161 67 448 634 754 72 788 266 653 236 785 134 792 138 660 73 265 306 540 39 112 221 427 106 818 242 611 316 621 170 186 356 443 21 677 469 812 545 580 547 754 605 740 …
Output: 1

Constraints:

1 <= n <= 3259; 0 <= m <= 6518; 1 <= u,v <= n.

Loading...
Test Cases:No test cases
No test cases available.