CT45640

Navigator and the Separate Camps

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

In the honeycomb cliffs of Beeswick, Navigator the store warden keeps careful count of the canals. Decode the foreman's shorthand notes, 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 <= 3050; 0 <= m <= 6100; 1 <= u,v <= n.

Example 1:

Input: 269 4363 21 249 73 133 11 81 70 203 49 126 73 145 119 256 135 158 31 144 7 128 233 248 23 168 148 212 7 95 116 182 183 267 163 177 157 241 202 241 11 235 69 86 83 192 46 109 143 235 106 253 170 250 90 114 78 260 164 247 29 74 114 268 159 227 9 211 183 249 149 253 91 238 251 257 6 9 214 234 86 131 165 264 84 209 41 136 201 257 163 225 51 150 182 208 19 239 165 229 8 14 233 269 65 205 147 225 229 263 122 187 184 214 41 118 17 157 25 109 60 119 57 269 58 183 141 165 192 195 90 193 160 168 82 163 33 164 31 234 150 251 72 99 149 217 135 173 3 265 43 185 18 32 152 180 10 98 49 133 25 268 33 259 126 258 256 261 80 265 9 97 22 195 170 204 44 194 52 149 180 202 36 245 44 181 45 155 85 100 154 180 47 121 35 72 153 156 32 153 14 164 22 68 203 217 79 242 20 56 11 199 51 196 14 248 77 110 168 224 88 15…
Output: 1

Example 2:

Input: 808 4879 60 547 267 739 361 612 11 456 173 678 253 659 80 311 305 458 135 292 76 725 426 511 141 285 515 764 57 647 326 355 213 317 95 784 554 601 214 492 16 288 503 583 420 599 628 668 728 772 600 647 233 464 32 194 7 655 301 549 373 767 518 686 14 740 198 345 143 583 474 559 555 702 2 791 530 531 115 476 202 256 483 616 618 786 698 770 203 520 627 719 484 576 2 462 157 585 548 654 499 725 74 493 455 598 325 556 299 347 284 733 577 635 628 660 76 583 3 729 228 366 156 282 83 307 279 309 529 730 123 583 257 344 273 666 364 680 397 483 606 769 552 594 493 666 721 756 94 506 96 730 293 647 49 600 206 676 107 291 107 208 110 389 241 279 159 652 18 749 184 684 246 787 201 425 74 573 404 737 569 570 386 493 329 636 175 648 439 805 62 545 375 515 220 392 417 649 425 538 367 637 87 610 238 723 18…
Output: 1

Example 3:

Input: 1876 5075 46 63 555 1468 242 988 416 923 339 763 372 1638 95 1341 97 1092 21 460 509 1669 144 1078 222 990 1638 1869 866 1272 959 1699 1055 1272 222 1860 88 614 1216 1304 994 1501 367 734 1342 1595 80 1684 11 938 78 1334 1310 1645 58 250 261 1170 467 1105 159 1863 142 1537 1728 1769 133 425 332 376 1035 1086 675 1221 94 1618 290 715 644 1559 281 1380 143 1144 877 1854 153 675 1037 1736 636 1246 847 1842 161 1667 445 595 687 1002 761 1186 910 1594 1582 1584 318 967 100 350 74 1706 616 679 1103 1854 785 1754 886 1834 95 347 783 1534 132 344 444 1300 294 546 149 1254 139 376 640 1621 602 701 1254 1745 1063 1125 610 1134 1577 1791 995 1766 381 441 100 1492 491 1523 562 1023 299 1543 94 1164 317 1071 173 621 1266 1751 937 1498 1254 1512 824 1385 171 938 538 599 153 1871 79 133 270 1314 1174 117…
Output: 5

Constraints:

1 <= n <= 3050; 0 <= m <= 6100; 1 <= u,v <= n.

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