CT33068

The Shimmerdeep Separate Camps

MediumL4 · Loop LordAcceptance: 0.0%XP: 35

In the opal reefs of Shimmerdeep, Jaya the clerk keeps careful count of the roads. Verify the safety inspections, 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 <= 1146; 0 <= m <= 2292; 1 <= u,v <= n.

Example 1:

Input: 792 2077 87 281 303 488 141 732 117 228 328 673 140 763 627 792 375 558 32 367 3 577 202 625 395 756 207 735 173 328 170 550 113 157 150 431 542 693 253 342 232 590 148 472 36 660 109 489 18 384 398 554 230 273 392 500 311 414 223 715 42 78 228 437 108 725 5 55 94 734 351 371 83 242 273 473 559 689 741 753 51 542 188 248 44 730 17 536 248 479 357 377 419 496 136 660 109 336 402 769 439 665 648 676 625 651 27 351 691 723 398 567 90 421 44 578 33 651 269 776 226 418 542 593 58 740 447 682 190 278 48 759 624 754 206 335 139 510 539 741 237 417 179 426 24 300 184 267 171 340 533 768 252 621 131 484 303 616 153 234 396 717 319 538 261 737 427 607 46 280 526 757 3 595 288 683 299 527 209 752 35 116 100 213 572 778 182 535 491 715 753 785 139 580 57 391 403 655 115 662 497 728 650 763 428 513 158…
Output: 7

Example 2:

Input: 1074 780 343 546 127 842 126 261 804 828 278 870 181 403 107 690 225 905 2 1005 353 852 206 577 233 935 213 951 794 855 553 768 217 784 199 715 333 1051 363 454 872 1049 832 1023 64 1022 501 689 455 763 123 779 719 761 209 837 11 366 5 414 205 341 222 777 332 976 277 818 95 671 381 1056 238 358 2 201 70 539 939 950 424 785 619 676 11 1023 153 338 404 538 936 990 774 994 252 449 60 121 219 1057 1 458 334 954 460 599 450 921 238 348 139 947 295 812 300 1035 697 727 687 785 133 146 511 678 174 509 569 1009 567 611 232 785 350 734 341 1044 98 615 229 954 233 302 201 1074 738 983 273 614 598 911 363 853 146 291 106 590 183 952 194 702 341 408 491 820 963 1005 130 951 579 795 510 861 756 796 901 918 496 964 35 165 242 788 170 270 208 444 157 996 699 833 12 471 324 341 81 1068 721 772 634 791 182…
Output: 324

Example 3:

Input: 1124 1271 176 245 49 284 463 1075 395 1009 111 214 773 790 347 742 395 599 436 591 308 537 423 1093 826 1013 45 705 29 562 156 299 489 603 140 1029 671 977 17 399 573 802 125 881 280 994 126 240 87 761 247 1053 909 980 344 658 137 600 636 822 513 598 303 433 783 877 75 730 480 915 449 742 958 1069 135 1041 459 668 366 987 735 1004 308 752 521 1071 174 515 6 697 744 953 233 485 841 937 245 936 917 959 165 942 577 671 93 486 41 601 268 1004 334 1095 404 725 466 1069 426 1039 819 834 873 898 268 448 827 925 194 848 258 978 754 984 582 844 101 1120 492 608 109 681 210 211 566 1016 175 1098 42 815 425 1092 459 1036 8 1002 548 845 399 723 41 113 246 652 208 628 276 615 128 214 58 630 187 432 445 606 578 627 329 880 307 756 164 1119 90 631 162 429 488 694 598 606 2 843 428 478 233 404 412 924 891…
Output: 132

Constraints:

1 <= n <= 1146; 0 <= m <= 2292; 1 <= u,v <= n.

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