CT31599

Admiral and the Separate Camps

MediumL4 · Loop LordAcceptance: 0.0%XP: 35

Admiral found an old ledger of roads in the timber yard attic at the gristmill of Rye Hollow. The margin notes pose a precise question. 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 <= 1338; 0 <= m <= 2676; 1 <= u,v <= n.

Example 1:

Input: 890 1592 621 780 219 581 179 740 148 801 686 755 203 869 627 799 78 553 259 770 196 693 98 580 14 250 59 392 461 753 629 676 74 131 53 415 829 855 179 312 211 709 695 874 284 809 376 657 4 624 549 829 32 87 179 369 869 870 424 480 223 234 196 227 219 638 686 772 83 564 132 133 224 635 55 672 92 101 262 658 523 632 7 42 280 554 72 554 342 429 347 753 100 874 145 291 4 279 166 820 5 38 312 847 594 763 440 441 234 530 385 744 179 520 696 712 143 443 325 504 138 607 227 276 201 609 94 628 84 627 144 702 281 510 276 552 21 449 368 469 92 667 397 791 202 493 305 418 576 604 161 633 22 781 483 538 364 826 540 565 81 247 591 849 44 844 359 729 417 764 632 757 562 676 288 410 105 678 205 428 48 740 463 716 7 714 143 227 405 606 603 795 136 751 707 750 301 308 239 410 126 403 479 594 411 655 11 711 …
Output: 25

Example 2:

Input: 1107 870 225 484 587 759 427 676 48 127 303 900 383 1057 161 452 60 297 186 712 46 119 94 1047 38 597 524 1052 247 668 83 654 452 606 40 686 20 703 492 703 527 991 66 918 538 612 226 397 110 382 340 734 242 437 51 1048 120 405 915 1025 254 387 22 603 491 637 250 463 6 477 538 800 900 1061 604 798 104 1030 205 632 527 748 271 737 146 926 663 906 725 827 711 1043 166 1009 599 643 749 832 502 802 108 605 394 1047 561 729 572 613 42 414 342 672 399 456 41 710 135 187 301 313 436 700 36 967 212 947 190 812 662 1021 485 651 211 595 398 1053 710 971 490 1029 838 1100 929 1011 84 699 510 699 934 949 158 861 1055 1060 144 752 583 724 112 583 1006 1069 637 1049 201 488 195 760 616 862 539 845 415 580 667 950 92 935 172 969 871 997 114 1096 131 291 105 652 558 1028 269 548 749 775 723 890 255 637 800…
Output: 284

Example 3:

Input: 580 1621 386 550 21 299 146 370 57 373 553 564 224 511 29 50 71 95 341 396 409 467 49 389 35 513 88 242 137 230 419 541 72 334 22 49 213 401 508 512 22 452 69 366 28 160 328 357 64 342 358 462 321 328 121 344 174 328 108 488 83 382 270 275 55 424 214 240 291 365 274 292 116 533 298 330 272 494 362 509 95 167 60 381 69 112 317 544 22 249 11 540 42 85 305 417 66 506 252 394 174 387 220 398 61 157 437 449 138 198 169 564 380 451 186 415 109 374 205 398 169 172 249 488 287 312 406 482 21 230 46 316 133 269 437 546 156 350 296 466 282 389 57 317 292 525 4 498 125 199 327 392 427 520 42 517 68 153 3 99 270 450 14 109 67 541 4 440 63 446 187 241 10 213 191 226 94 480 81 193 405 490 95 411 185 188 322 393 371 484 42 453 29 356 271 444 229 282 164 345 273 473 362 458 6 171 185 580 221 575 100 495 3…
Output: 4

Constraints:

1 <= n <= 1338; 0 <= m <= 2676; 1 <= u,v <= n.

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