CT55903

Keeper Counts the tunnels

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Caravans arrive at the steppe camp of Horselord Plains with crates of tunnels, and Keeper the accountant must account for every last one. 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 <= 1332; 0 <= m <= 2664; 1 <= u,v <= n.

Example 1:

Input: 1328 2659 150 1012 180 351 497 720 236 895 406 555 15 654 515 1259 500 1315 92 1130 328 863 684 1144 492 961 783 1190 106 411 984 1202 1162 1268 858 1265 940 1262 740 827 45 84 870 1204 348 438 119 1122 227 765 479 972 331 580 1035 1270 961 1195 234 839 361 1064 970 1025 444 1201 639 1287 924 1267 754 1233 253 1118 83 424 15 1268 831 1141 582 999 442 695 58 76 966 1058 274 984 230 973 837 1283 951 1289 438 799 217 344 690 721 292 1213 39 456 3 795 731 732 300 1155 151 254 9 1305 57 163 770 961 122 714 260 276 101 407 1010 1213 69 530 223 1085 525 701 509 896 132 730 343 900 1128 1196 686 699 626 1130 263 484 138 796 850 1150 323 949 481 535 213 376 535 1263 70 103 180 1275 226 387 637 799 1014 1142 969 1244 727 911 913 1105 327 924 740 1120 344 456 257 295 67 470 771 1018 1039 1121 845 119…
Output: 29

Example 2:

Input: 909 2650 44 725 127 692 512 726 215 392 114 411 98 365 67 593 159 716 250 496 602 881 199 738 654 657 123 307 86 280 92 810 206 383 292 302 4 548 55 138 129 883 342 790 316 636 100 644 316 588 116 188 345 811 648 654 216 351 283 599 228 669 384 733 134 150 442 532 588 751 563 705 5 764 358 836 151 620 578 826 432 528 561 611 247 582 119 888 79 435 368 469 267 810 207 582 478 731 193 268 228 338 287 372 181 524 110 573 27 896 425 493 559 814 437 696 317 876 640 755 466 866 273 572 141 441 111 679 61 830 74 736 277 855 145 388 472 818 41 55 155 647 594 675 327 569 20 323 262 349 427 601 114 492 445 781 138 344 131 308 478 784 299 533 528 535 394 433 30 851 731 830 255 747 517 881 75 163 235 265 214 815 619 678 183 789 596 852 243 750 77 80 132 521 49 356 282 896 571 645 418 600 129 498 339 5…
Output: 4

Example 3:

Input: 989 541 291 942 582 861 253 555 131 642 355 482 477 532 60 362 10 782 128 198 241 399 660 955 74 404 88 696 18 628 521 975 40 625 28 168 189 363 851 980 575 706 350 876 175 665 34 182 158 688 211 638 660 769 614 663 301 888 389 646 541 676 351 459 449 552 399 941 170 686 659 721 704 900 707 784 346 460 587 701 384 940 357 361 241 811 793 857 34 94 325 771 79 208 367 605 111 758 139 568 649 854 7 83 363 645 152 605 115 138 75 942 135 856 53 66 147 906 687 876 270 645 353 519 816 860 415 436 247 672 464 729 267 980 803 837 309 456 36 731 562 729 333 828 302 400 337 366 717 813 165 547 225 341 580 922 346 367 850 857 477 954 300 653 708 927 36 893 304 690 326 621 593 654 495 683 188 721 64 770 325 528 404 868 53 360 471 819 340 777 664 862 62 980 197 216 252 436 168 956 181 731 284 642 139 26…
Output: 449

Constraints:

1 <= n <= 1332; 0 <= m <= 2664; 1 <= u,v <= n.

Loading...
Test Cases:No test cases
No test cases available.
Keeper Counts the tunnels - MEDIUM Coding Problem | CodeTikki