CT34305

The Separate Camps of the Twilight canals

MediumL4 · Loop LordAcceptance: 0.0%XP: 35

In the anvil district of Hammerfall, Lara the bookkeeper keeps careful count of the canals. win the guild's seasonal contest, 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 <= 1182; 0 <= m <= 2364; 1 <= u,v <= n.

Example 1:

Input: 524 748 133 166 116 125 36 126 69 291 277 313 66 104 191 270 32 306 213 368 37 194 62 75 410 494 55 90 120 264 19 480 218 485 241 515 87 231 90 345 23 412 183 313 200 351 422 444 16 301 81 356 56 445 322 342 310 482 197 504 125 267 293 507 240 406 290 302 22 504 261 276 120 244 300 524 19 482 206 372 40 75 411 484 329 523 8 104 153 199 396 414 111 312 146 482 189 397 83 335 333 498 150 444 147 504 135 279 13 181 151 385 21 279 93 103 191 253 67 468 41 467 91 254 290 294 220 287 88 487 207 330 256 449 139 301 212 451 250 418 374 469 230 464 374 416 411 476 261 380 311 398 403 483 167 446 389 417 231 386 277 363 89 524 306 329 327 475 228 306 22 82 371 402 111 417 150 319 301 432 214 237 205 295 436 491 175 283 28 520 295 459 86 463 126 258 207 222 258 416 80 326 24 348 304 358 123 195 11 50…
Output: 25

Example 2:

Input: 1115 725 72 598 688 759 34 487 271 765 277 581 359 850 825 986 136 573 72 74 562 900 603 645 54 356 456 1076 888 930 253 488 309 602 638 653 45 991 318 620 133 760 803 855 209 782 837 965 911 1022 238 641 463 688 777 795 857 1051 143 642 607 932 253 613 55 998 319 527 30 270 135 830 529 612 382 505 662 836 121 752 126 427 458 1075 380 1033 301 980 51 416 641 776 171 885 272 1033 1041 1066 388 769 398 496 143 362 202 272 181 611 808 965 170 606 58 110 310 880 90 1083 595 722 59 470 676 999 717 1008 272 1009 469 630 779 1003 424 583 328 705 275 654 810 845 493 592 105 549 180 196 579 677 170 877 617 1013 310 579 57 992 428 557 137 788 393 718 88 897 160 654 634 729 696 780 222 671 607 741 606 826 1034 1062 220 280 332 824 6 339 462 920 79 699 291 918 173 432 178 205 151 1104 841 866 437 788 …
Output: 401

Example 3:

Input: 923 1055 316 886 385 618 128 417 48 768 137 719 496 736 181 608 659 918 52 847 125 698 86 612 275 558 613 755 394 864 48 424 374 804 10 427 20 636 238 398 66 82 32 843 591 633 50 461 286 561 423 632 385 522 355 920 589 705 184 270 92 581 364 539 588 622 36 551 546 630 155 754 132 526 706 871 395 402 299 329 401 631 186 230 638 850 313 858 628 640 50 162 36 630 187 875 831 843 541 823 475 519 40 617 356 899 426 830 327 503 29 259 429 659 573 884 555 902 405 891 466 843 95 442 55 687 333 492 328 782 329 902 369 624 32 559 446 482 305 444 600 879 565 741 260 396 426 445 522 725 530 616 21 207 521 696 46 818 57 515 149 363 408 728 62 285 77 563 623 873 387 444 2 197 543 815 107 192 195 493 66 516 634 910 605 686 62 376 345 541 435 700 656 817 25 492 283 763 147 825 272 888 421 636 408 918 322 …
Output: 92

Constraints:

1 <= n <= 1182; 0 <= m <= 2364; 1 <= u,v <= n.

Loading...
Test Cases:No test cases
No test cases available.
The Separate Camps of the Twilight canals - MEDIUM Coding Problem | CodeTikki