CT45949

The Separate Camps at Keelwind

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Morning light hits the shipyard of Keelwind as Lara unrolls the day's manifest of routes. The tally will decide the next shipment. 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 <= 3516; 0 <= m <= 7032; 1 <= u,v <= n.

Example 1:

Input: 638 1021 80 411 108 162 317 417 75 522 180 546 335 476 198 202 25 581 206 248 50 357 312 630 420 447 291 292 96 611 124 135 59 283 248 326 118 453 393 578 253 461 313 415 304 636 342 523 388 612 280 483 255 598 187 452 171 566 70 565 159 448 13 480 56 401 275 614 201 335 256 435 378 474 93 551 207 305 5 332 159 340 38 351 445 489 45 428 323 405 377 606 448 574 209 359 148 153 313 632 231 630 419 427 283 495 65 70 111 236 380 417 281 453 52 360 59 546 117 427 555 616 330 613 379 557 23 323 56 627 256 390 69 430 12 287 101 519 243 431 231 402 297 551 216 392 177 307 115 588 53 224 27 546 242 278 133 394 365 576 156 211 239 632 336 592 439 489 75 380 204 209 253 434 289 442 148 375 15 308 248 420 449 595 167 335 55 515 520 548 197 382 312 327 299 634 276 278 388 408 143 580 15 127 215 610 19 …
Output: 27

Example 2:

Input: 3300 710 413 2387 423 2227 131 2965 380 477 83 278 1680 1783 482 1209 2612 2826 469 2721 706 1338 129 1592 1993 2074 87 3164 2402 2808 978 3168 950 1788 1723 2996 1194 1721 1438 2439 2015 2710 484 2944 722 2049 1229 1830 1228 1894 694 3020 1060 2848 1229 2437 2253 2897 1066 2980 2610 3033 314 1906 1851 2559 332 2550 207 352 325 2630 393 2334 98 2376 1367 3263 877 3191 870 1758 1251 2837 938 2392 1055 2729 1299 2517 1666 2194 1503 1894 1623 2220 969 1500 111 3239 1197 1804 504 2530 685 795 1099 1734 2484 2763 2615 3153 656 2055 1956 2903 880 3066 1397 2657 503 2757 291 1522 3102 3237 1518 2667 531 2727 1289 1802 1722 1965 1233 2574 1469 2350 1589 3069 1676 1981 1802 2607 892 1561 2426 2922 285 2483 339 2995 1669 3296 128 1870 806 2769 1898 3287 814 2374 2676 2843 795 2257 515 1560 233 2438 …
Output: 2590

Example 3:

Input: 1056 4216 383 796 99 266 164 951 806 1008 317 1039 181 844 234 682 243 637 544 985 280 398 258 943 190 372 581 888 265 723 572 1048 671 765 490 533 248 364 96 321 225 458 213 750 301 877 278 956 545 994 269 561 142 218 661 738 11 835 274 972 408 960 20 999 318 957 440 856 262 704 690 717 716 975 5 785 253 703 69 666 618 744 749 1011 638 732 59 420 128 645 42 949 312 633 67 393 185 323 394 779 399 438 479 827 537 1050 428 598 118 197 173 841 697 793 265 566 723 765 312 368 234 925 372 862 23 198 63 419 121 711 178 642 335 672 208 909 337 490 290 924 397 690 984 1046 73 716 3 27 688 756 79 198 399 781 133 1010 81 273 663 738 370 616 540 579 391 815 252 967 598 882 543 977 37 929 315 657 337 446 495 671 106 417 16 315 234 1007 794 961 282 307 1 559 380 684 71 318 3 762 488 841 834 949 698 930…
Output: 3

Constraints:

1 <= n <= 3516; 0 <= m <= 7032; 1 <= u,v <= n.

Loading...
Test Cases:No test cases
No test cases available.
The Separate Camps at Keelwind - MEDIUM Coding Problem | CodeTikki