CT29264

The Separate Camps of Deepwater

MediumL4 · Loop LordAcceptance: 0.0%XP: 35

At the fjord village of Deepwater, Tanner records each routes 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 <= 1839; 0 <= m <= 3678; 1 <= u,v <= n.

Example 1:

Input: 777 2893 387 618 361 424 577 724 413 617 23 48 678 723 145 165 465 610 318 621 97 303 133 722 47 185 253 333 327 601 175 534 248 612 635 689 145 368 201 348 255 264 362 434 166 687 16 112 190 321 119 621 284 393 20 336 460 617 57 629 103 630 261 501 374 572 475 624 222 530 131 215 181 234 103 460 567 759 363 775 314 358 61 405 629 744 126 492 49 265 109 477 414 616 103 550 243 462 352 577 646 702 520 762 69 81 208 562 83 442 307 706 206 676 388 565 544 683 245 349 218 736 63 405 164 662 175 407 485 743 412 702 294 446 47 503 280 690 245 775 547 585 261 406 133 533 135 505 252 469 538 550 494 764 158 648 281 412 283 487 278 302 185 383 159 354 55 232 17 673 184 611 378 609 258 478 449 636 17 399 149 761 113 624 334 542 323 357 143 513 141 754 71 637 451 653 489 754 4 436 361 759 661 674 314…
Output: 2

Example 2:

Input: 158 1354 1 73 30 35 74 147 6 111 2 27 121 139 17 148 94 148 46 83 59 148 87 101 40 59 13 21 42 121 24 78 104 126 21 45 77 110 53 86 78 148 61 135 102 157 14 41 60 119 134 147 50 84 86 156 78 151 127 128 8 55 67 148 87 140 72 120 4 51 32 66 103 111 26 30 21 44 44 130 59 146 98 108 78 91 73 136 57 111 27 105 4 97 78 94 59 109 70 76 65 150 41 122 44 138 39 92 58 143 5 7 56 71 81 91 15 29 29 57 8 156 8 145 25 86 1 33 12 53 38 75 38 47 48 97 56 137 95 155 13 146 109 119 8 33 7 20 44 59 101 133 11 127 34 45 71 137 8 92 7 118 143 146 17 42 3 116 109 115 10 104 30 124 25 110 61 83 3 114 102 123 5 36 27 143 30 73 90 121 42 117 30 38 17 68 21 119 17 85 42 91 30 152 63 95 85 153 109 142 7 38 106 132 1 60 56 104 66 100 52 81 130 142 5 147 2 22 11 26 56 140 75 148 122 136 36 146 87 107 49 108 55 102 97…
Output: 1

Example 3:

Input: 171 2494 90 94 55 112 57 75 39 124 51 125 27 41 2 72 97 140 15 157 59 82 91 164 76 93 71 135 43 110 25 152 34 56 130 164 48 101 9 110 45 59 112 171 67 119 41 157 56 71 121 155 35 47 33 144 73 124 66 69 18 158 39 154 27 116 154 159 14 28 71 142 70 102 153 167 11 70 117 132 50 108 145 158 6 96 38 122 67 76 24 122 74 142 101 160 5 104 3 39 149 154 85 152 150 167 17 111 49 158 46 60 148 159 46 171 10 142 64 158 51 75 78 119 12 24 11 108 84 115 31 112 65 123 10 120 31 62 41 103 79 111 14 82 28 160 5 110 49 101 96 98 14 30 11 48 67 123 149 161 108 120 28 45 51 153 36 86 79 115 57 89 79 114 148 157 46 140 70 82 120 124 109 123 67 87 32 99 9 164 5 126 72 125 50 167 153 159 105 118 56 124 101 161 6 53 103 144 93 143 125 153 94 118 76 135 70 101 7 165 44 76 90 122 95 98 101 115 77 123 49 78 77 145 1…
Output: 1

Constraints:

1 <= n <= 1839; 0 <= m <= 3678; 1 <= u,v <= n.

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