CT37839

Mira's Northern bridges

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

The inventory keeper Mira has been asked to outscore the rival chapter. On the desk lies a long table of bridges readings. 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 <= 2068; 0 <= m <= 4136; 1 <= u,v <= n.

Example 1:

Input: 1496 60 369 787 778 1314 352 1069 390 1068 383 395 430 681 698 1068 831 1338 1203 1463 484 555 225 267 1204 1304 447 947 318 554 78 1284 1143 1278 668 1050 698 873 717 1374 267 954 312 1301 207 1325 96 191 777 786 562 1485 319 529 52 190 18 1140 308 1256 533 1017 340 540 287 1097 775 813 902 1212 1272 1313 822 1146 981 1079 261 1119 178 536 79 264 1112 1121 1330 1413 345 1214 757 1136 292 1014 990 1356 59 645 62 1128 753 1042 940 1081 1213 1229 682 1031 679 791 1126 1227 655 1271 244 1362 217 396 194 774 641 1229 855 1231
Output: 1436

Example 2:

Input: 1112 3400 254 807 117 357 331 1043 177 186 653 995 118 587 943 955 873 1029 998 1087 256 750 25 412 58 644 509 666 162 605 595 909 283 349 262 1017 382 1006 86 360 220 1034 31 543 572 827 213 580 255 425 741 1020 271 1111 930 985 239 581 252 477 769 1056 364 957 620 745 192 416 893 1096 929 1112 257 996 415 861 340 962 120 564 504 759 619 685 900 1006 240 622 642 836 469 785 255 939 787 905 331 710 879 1078 980 1101 268 1099 172 594 101 777 563 774 470 620 86 677 694 904 402 1010 424 460 885 934 166 676 713 797 154 615 152 638 85 331 499 622 544 821 15 817 284 993 89 156 608 1103 86 953 538 600 516 1040 750 847 11 902 830 1081 37 440 25 375 357 553 528 708 1049 1107 199 708 911 1078 632 915 86 326 481 1049 266 726 111 463 757 975 119 310 323 441 553 613 586 652 253 688 599 602 844 1016 108…
Output: 2

Example 3:

Input: 1056 3105 716 1021 164 206 457 897 546 1003 207 703 795 986 296 863 57 632 14 381 37 984 775 896 49 564 83 484 180 911 249 837 43 147 317 1025 279 477 308 431 331 378 177 881 154 460 14 122 150 668 132 943 409 886 22 761 159 247 850 861 95 692 321 474 83 864 424 477 203 771 183 844 220 304 261 736 626 657 180 312 359 843 563 893 411 727 74 359 377 537 9 590 928 938 496 913 401 429 347 674 661 774 366 596 24 568 145 260 68 470 241 700 173 739 636 826 517 644 412 709 750 882 512 939 246 949 93 526 58 946 420 536 23 170 447 1001 498 881 344 670 380 785 121 606 141 881 198 931 85 1000 38 597 291 450 142 716 801 866 582 1019 172 927 543 764 827 877 361 606 607 844 215 654 397 702 76 851 90 94 46 133 640 982 206 672 808 927 220 373 168 366 801 904 376 620 370 964 689 1022 143 175 105 988 401 813…
Output: 6

Constraints:

1 <= n <= 2068; 0 <= m <= 4136; 1 <= u,v <= n.

Loading...
Test Cases:No test cases
No test cases available.
Mira's Northern bridges - MEDIUM Coding Problem | CodeTikki