CT39217

Tinker's Pearl Ledger

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

At the lotus ponds of Tranquil Basin, Tinker records each roads in a worn leather ledger. The guild wants answers, not guesses. 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 <= 3126; 0 <= m <= 6252; 1 <= u,v <= n.

Example 1:

Input: 1121 1114 36 1067 41 190 632 672 50 855 600 775 390 997 782 1091 30 485 292 679 524 1083 575 934 444 948 540 998 210 311 663 711 193 883 310 834 367 1050 619 751 309 348 117 899 899 1025 321 792 155 1074 412 894 743 908 524 700 330 887 584 638 431 905 325 513 356 690 668 742 518 941 271 969 388 941 118 766 383 961 168 1079 282 379 107 837 180 658 545 694 73 607 93 1070 60 1005 812 1069 653 993 265 303 165 293 751 981 686 953 243 872 471 967 704 949 46 745 643 668 159 675 602 878 156 953 1029 1081 41 76 512 599 44 158 345 913 241 711 446 664 107 356 208 695 715 774 228 695 153 518 304 695 765 867 59 537 789 798 174 869 566 837 467 956 388 1068 476 849 64 205 576 1015 487 1065 452 610 606 954 336 966 526 1005 5 1115 124 345 410 524 54 330 616 820 347 910 168 683 23 203 215 406 521 917 783 10…
Output: 186

Example 2:

Input: 969 2975 113 482 134 249 287 664 511 734 689 885 148 449 180 673 60 488 60 491 386 466 318 580 98 320 93 676 351 935 123 758 527 739 647 879 334 400 77 847 160 454 92 128 425 877 50 939 461 903 5 953 138 823 563 815 76 642 274 555 530 840 365 809 96 580 839 910 371 832 149 306 262 955 31 818 739 789 195 740 7 56 327 863 127 419 206 730 476 766 640 674 912 925 374 932 857 914 113 235 279 357 46 186 658 823 143 901 84 758 256 841 555 779 159 180 622 691 523 777 164 307 352 449 254 650 248 738 52 475 25 444 182 266 115 562 186 659 790 958 494 905 271 591 413 641 341 724 234 271 386 967 391 773 227 629 867 913 45 821 109 620 471 873 191 543 36 851 717 911 254 577 181 704 172 561 36 674 551 674 660 691 314 846 767 870 791 963 110 131 492 928 198 312 764 766 144 625 118 689 414 507 534 659 325 6…
Output: 2

Example 3:

Input: 227 58 116 119 85 204 117 204 69 183 23 123 12 46 36 93 8 202 128 137 73 108 93 103 97 226 6 12 130 139 22 175 33 180 134 226 138 154 67 167 171 213 139 194 104 223 57 181 50 208 101 137 52 200 99 114 64 161 19 132 2 55 53 130 188 209 14 201 82 210 88 168 99 155 118 175 103 222 88 187 193 217 13 83 67 158 14 47 9 92 1 5 62 218 161 206 40 139 9 202 25 140 6 107 163 199 82 213 6 48 37 174 4 38 118 205 60 122
Output: 169

Constraints:

1 <= n <= 3126; 0 <= m <= 6252; 1 <= u,v <= n.

Loading...
Test Cases:No test cases
No test cases available.
Tinker's Pearl Ledger - MEDIUM Coding Problem | CodeTikki