CT32164

Piper's Separate Camps Ledger

MediumL4 · Loop LordAcceptance: 0.0%XP: 35

It is audit day at the honeycomb cliffs of Beeswick. Piper spreads the corridors records across the table and picks up a sharp pencil. 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 <= 1127; 0 <= m <= 2254; 1 <= u,v <= n.

Example 1:

Input: 1005 1908 165 642 146 427 289 470 637 680 335 434 734 960 89 588 498 804 115 724 124 362 233 811 124 505 735 736 198 945 467 697 194 915 36 819 46 96 185 911 312 480 710 880 370 731 236 684 201 467 48 934 790 954 559 1003 623 799 888 995 359 502 140 558 62 70 388 722 213 773 888 941 676 972 164 894 92 870 171 517 5 172 179 883 598 872 417 471 25 184 91 422 888 897 74 653 468 850 32 991 11 470 336 450 125 638 788 915 360 859 59 313 193 468 570 843 139 845 837 918 89 847 705 796 83 767 809 853 319 350 147 342 221 359 93 528 192 967 880 933 20 905 562 705 432 993 127 650 38 129 28 44 622 715 223 629 963 993 304 722 583 721 138 190 948 949 106 845 242 647 392 866 772 813 502 764 140 771 354 523 581 692 30 291 872 959 485 542 903 982 677 733 833 994 179 939 279 419 548 589 332 837 721 932 314 6…
Output: 13

Example 2:

Input: 1018 969 16 554 107 910 608 706 456 640 368 743 336 408 228 712 56 131 296 936 419 737 350 954 370 551 120 366 325 461 571 737 207 636 197 467 28 997 211 1014 12 414 392 905 118 912 777 816 646 977 713 907 133 232 966 1011 395 462 531 566 263 987 581 1004 713 777 31 835 632 874 260 853 251 371 764 979 424 593 64 934 85 212 116 974 307 1009 39 805 18 845 385 1000 54 960 350 424 755 932 371 709 410 508 56 322 679 848 748 752 59 118 26 45 159 788 56 262 153 370 766 816 157 785 578 790 71 149 803 854 518 712 3 499 416 820 539 885 136 493 489 989 442 1008 675 701 607 917 485 604 178 728 487 549 230 326 460 1013 160 675 104 773 221 948 227 558 92 786 364 674 205 890 433 1004 377 560 423 982 674 876 270 375 35 445 933 964 408 483 294 717 194 808 386 685 218 929 354 544 55 417 84 614 9 71 105 1011…
Output: 176

Example 3:

Input: 537 2219 76 510 21 298 23 523 358 450 47 86 382 442 164 449 59 285 141 190 7 223 198 270 443 456 421 477 105 316 429 457 141 452 134 246 4 271 307 485 373 464 146 191 177 503 200 277 41 168 289 410 242 255 11 165 34 229 292 448 3 299 35 316 57 360 243 444 217 344 20 253 175 239 400 535 23 192 164 451 123 225 288 320 332 527 127 357 110 377 79 248 428 453 336 508 299 494 199 214 214 520 12 163 461 508 113 404 348 516 290 345 234 383 137 138 318 383 230 287 479 489 7 112 180 496 343 373 41 363 1 73 128 316 353 503 234 331 47 183 38 71 275 404 334 356 405 516 114 356 129 503 55 489 44 301 219 301 183 424 159 203 126 329 369 375 198 421 75 154 245 424 177 431 171 419 60 484 30 530 178 510 206 422 107 439 276 279 60 368 96 178 300 362 39 411 389 395 390 490 132 186 213 471 177 537 118 353 45 38…
Output: 2

Constraints:

1 <= n <= 1127; 0 <= m <= 2254; 1 <= u,v <= n.

Loading...
Test Cases:No test cases
No test cases available.
Piper's Separate Camps Ledger - MEDIUM Coding Problem | CodeTikki