CT35836

The Separate Camps Beneath Bramblecourt

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Nora runs the mill at the thorn maze of Bramblecourt. Today the books show a list of routes, and the numbers must be worked out before sundown. 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 <= 1911; 0 <= m <= 3822; 1 <= u,v <= n.

Example 1:

Input: 797 348 305 615 287 534 528 635 91 788 62 160 272 581 61 298 177 188 486 628 3 725 567 577 55 700 437 452 333 606 397 750 428 747 43 499 218 329 344 431 25 617 151 438 20 308 579 619 150 489 675 701 633 728 76 106 115 384 75 219 116 576 121 646 374 516 180 650 503 697 120 578 372 500 174 460 453 517 162 179 283 523 208 580 81 724 177 571 149 381 169 757 35 681 129 228 70 567 661 772 95 121 33 163 572 592 614 742 711 760 48 661 432 698 449 530 22 568 245 366 295 666 102 374 67 482 208 426 436 457 145 712 400 595 204 661 431 448 704 742 690 724 80 344 204 217 356 743 1 431 122 233 40 204 470 532 62 287 528 682 331 644 174 752 455 647 199 460 716 768 117 650 124 161 248 469 217 381 83 215 441 615 431 455 81 749 268 593 199 404 360 734 419 601 439 716 575 727 239 473 126 514 49 600 210 318 243…
Output: 450

Example 2:

Input: 165 3024 11 42 66 153 74 143 17 129 17 47 65 117 32 117 79 114 32 96 45 135 1 79 126 127 8 87 113 154 98 163 67 138 29 107 128 160 41 70 91 111 21 78 57 59 62 145 4 28 17 136 116 147 11 83 86 118 20 97 100 130 75 128 64 109 109 125 54 113 129 131 52 75 9 65 75 141 84 88 69 101 50 79 20 21 144 164 61 117 24 165 80 160 44 56 65 138 10 73 27 124 32 160 1 142 12 81 151 155 68 140 46 129 132 164 9 48 19 144 43 98 91 125 57 93 60 165 42 95 58 157 65 70 29 60 82 163 10 128 95 149 46 121 7 67 8 21 61 92 10 127 31 124 52 74 35 164 35 122 35 97 29 149 10 46 23 134 73 123 15 89 18 140 103 107 8 109 42 48 42 52 53 79 14 136 3 56 133 156 34 111 68 114 112 122 48 129 59 91 17 143 105 111 61 110 2 158 132 146 78 95 146 150 69 163 78 150 79 92 87 146 48 131 41 125 8 138 4 155 6 95 79 113 15 80 53 54 64 73…
Output: 1

Example 3:

Input: 1036 2115 662 1019 7 611 221 808 630 707 66 111 372 418 33 132 145 858 755 969 35 698 628 786 156 361 550 817 373 836 250 476 582 672 120 221 494 1027 385 727 377 1004 255 978 254 606 152 412 309 478 65 862 34 613 150 823 591 789 28 791 532 776 543 936 279 976 668 798 538 762 635 925 105 420 733 745 167 824 82 685 149 800 78 956 225 1033 425 809 345 588 156 411 107 385 42 136 316 674 198 829 250 894 528 668 339 340 595 927 153 453 318 803 1 762 741 897 21 535 630 934 343 794 817 951 190 626 73 421 36 504 363 412 112 195 64 1013 119 130 387 432 939 941 332 520 153 262 24 480 291 551 118 749 325 486 318 523 258 381 158 648 342 463 17 177 273 467 576 661 345 891 62 684 321 931 648 742 368 652 39 183 332 465 17 99 409 868 178 1033 361 510 5 727 534 884 520 1006 376 439 276 335 23 839 200 847 5…
Output: 17

Constraints:

1 <= n <= 1911; 0 <= m <= 3822; 1 <= u,v <= n.

Loading...
Test Cases:No test cases
No test cases available.