CT39851

Aldo's Pearl bridges

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Aldo the quartermaster watches over the ember mines of Cindercrag's stores of bridges. A careful computation stands between order and chaos. 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 <= 2101; 0 <= m <= 4202; 1 <= u,v <= n.

Example 1:

Input: 838 770 339 810 441 711 472 735 416 453 96 307 336 737 314 634 58 616 368 635 196 288 739 756 349 459 244 452 215 249 29 333 788 833 355 491 319 695 305 642 778 819 647 789 430 823 213 502 120 389 135 632 584 811 598 760 529 837 642 719 93 294 107 382 38 711 599 809 383 837 520 748 332 679 234 672 102 307 99 109 32 656 189 423 504 509 142 314 501 631 329 713 164 561 164 352 142 558 186 619 283 569 458 590 635 677 49 371 21 820 12 573 213 573 200 340 555 604 256 713 223 251 99 633 211 396 448 609 649 809 151 294 249 453 433 767 189 340 172 800 125 140 487 501 142 206 373 407 84 809 5 576 150 362 381 631 7 232 101 701 229 512 170 554 46 425 415 725 40 92 37 564 309 801 146 556 26 134 16 814 632 634 521 644 237 795 449 727 503 612 397 746 160 781 102 161 293 726 48 576 725 762 298 619 458 539…
Output: 167

Example 2:

Input: 1047 2882 36 758 170 673 839 938 131 153 167 705 338 938 931 1014 178 850 202 798 377 1001 601 986 48 984 14 546 403 903 274 853 361 855 149 216 386 1000 227 279 70 594 420 678 288 901 157 294 231 393 686 1018 131 578 384 872 46 287 28 327 264 780 32 392 823 911 436 458 168 279 166 583 339 473 254 288 448 711 305 885 357 705 169 646 346 620 251 478 134 225 56 510 9 649 493 648 423 718 239 615 264 1034 206 526 206 637 680 908 938 953 368 451 13 61 887 959 194 438 813 906 403 630 38 880 81 415 269 847 738 896 407 919 132 268 441 748 336 338 20 227 373 636 272 744 301 406 311 401 201 995 707 1034 592 658 76 464 203 236 622 686 158 457 768 946 232 344 166 652 700 832 515 737 115 379 347 1041 107 200 712 923 596 623 617 904 2 983 258 798 95 624 216 326 397 872 159 574 337 635 562 792 327 739 23…
Output: 6

Example 3:

Input: 249 2849 156 247 141 163 109 140 191 236 148 228 24 55 141 147 36 235 106 131 87 150 47 101 85 99 51 90 42 130 48 219 125 216 10 53 29 157 55 185 66 76 92 139 121 225 32 135 20 105 67 226 153 172 15 146 83 233 9 240 81 232 115 153 101 112 245 246 8 202 98 113 17 83 123 225 128 242 17 185 109 143 42 43 43 62 71 222 184 244 172 237 1 233 156 226 20 193 111 189 82 227 227 233 41 201 123 200 50 241 58 72 19 194 86 216 90 99 224 234 197 221 147 221 25 91 10 140 59 89 163 171 85 162 157 211 38 118 34 246 123 179 38 93 70 81 147 240 37 191 65 172 47 178 93 234 36 133 141 227 79 214 32 189 8 106 25 221 103 233 127 166 33 57 79 231 53 247 83 235 47 95 16 225 76 166 130 206 79 103 31 220 68 100 82 212 65 94 70 242 21 161 89 99 43 143 90 109 107 120 175 237 4 107 179 240 142 194 117 130 94 174 61 189…
Output: 1

Constraints:

1 <= n <= 2101; 0 <= m <= 4202; 1 <= u,v <= n.

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