CT29785

The Separate Camps of Silverfin

MediumL4 · Loop LordAcceptance: 0.0%XP: 35

Lila inherited the ropewalk at the herring shoals of Silverfin along with its curious bookkeeping system for routes. Time to make sense of it. 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 <= 1348; 0 <= m <= 2696; 1 <= u,v <= n.

Example 1:

Input: 1089 1714 483 850 385 498 63 210 684 816 20 426 477 944 301 361 3 998 675 971 14 497 542 571 342 773 76 802 471 730 562 569 733 1012 751 1073 671 707 489 660 678 1077 480 672 577 586 655 932 114 269 8 13 487 832 785 907 836 1001 807 842 803 969 747 857 152 875 241 997 244 913 135 700 213 514 909 914 174 642 408 976 371 528 528 1035 445 700 188 658 709 1033 431 1049 465 827 362 623 45 478 723 815 200 371 400 533 153 454 518 526 565 846 261 408 194 1088 817 1077 516 749 319 1089 746 832 580 850 388 574 150 395 461 1029 282 805 864 868 331 875 974 1022 82 362 1019 1023 441 875 257 792 722 1086 995 1025 909 1030 360 1053 181 358 402 440 418 744 659 866 484 1025 88 171 19 334 45 786 640 1019 176 958 400 852 224 769 220 253 79 219 290 739 465 509 30 188 31 929 267 1001 392 1080 853 930 507 630 1…
Output: 41

Example 2:

Input: 978 2525 949 978 498 834 121 748 786 935 356 653 295 383 600 678 162 475 548 780 3 686 133 475 437 923 520 790 400 517 276 744 541 802 291 693 590 949 34 436 591 764 339 459 501 616 295 761 30 108 578 900 324 821 260 520 823 924 284 770 273 602 426 815 570 720 648 928 708 740 569 738 23 216 72 859 225 319 371 652 584 607 746 887 359 955 606 713 9 204 269 523 198 623 642 975 337 887 209 511 46 864 45 504 183 631 886 917 15 70 707 952 64 217 401 656 445 513 356 364 558 741 700 795 246 680 98 475 29 487 140 796 318 973 108 491 14 698 627 926 819 962 272 423 236 265 190 757 555 887 277 506 80 930 231 271 615 833 210 794 173 619 226 493 355 377 31 477 224 550 596 848 755 861 805 807 877 943 298 423 249 348 206 878 236 597 95 686 678 786 424 599 113 854 142 680 69 721 235 757 161 922 155 531 428…
Output: 6

Example 3:

Input: 711 227 320 433 163 615 312 661 203 299 629 673 533 633 143 448 196 329 2 370 332 368 634 683 398 610 87 437 453 535 130 213 390 427 315 563 81 215 116 502 610 678 113 292 142 650 177 419 228 233 368 376 275 473 191 439 114 593 57 235 41 554 453 468 592 637 478 641 32 692 258 642 47 233 47 592 285 390 181 577 465 584 89 307 279 557 82 163 67 210 80 643 17 277 85 419 344 705 340 549 342 432 518 639 254 286 195 677 463 628 446 624 244 347 137 363 665 687 180 309 500 503 269 536 121 432 73 100 61 435 49 111 81 260 266 624 291 490 287 471 497 706 337 649 239 679 126 320 268 517 69 523 320 348 477 687 412 615 60 544 393 593 112 551 244 557 147 687 193 447 136 408 5 502 445 653 382 573 369 487 17 440 560 581 50 149 391 403 535 571 142 600 75 91 431 587 513 647 52 344 269 371 29 584 87 415 179 65…
Output: 484

Constraints:

1 <= n <= 1348; 0 <= m <= 2696; 1 <= u,v <= n.

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