CT29403

Marble routes Separate Camps

MediumL4 · Loop LordAcceptance: 0.0%XP: 35

Legend says the vault under the lantern reef of Glowtide opens only for a perfect tally of routes. Mason means to find out. 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 <= 1046; 0 <= m <= 2092; 1 <= u,v <= n.

Example 1:

Input: 989 1740 99 291 50 983 333 958 547 825 236 784 353 398 329 895 248 981 396 416 148 836 298 586 13 27 340 699 61 535 92 124 376 732 158 470 478 622 485 690 284 716 90 403 233 366 240 868 54 713 51 261 845 964 416 833 225 616 539 795 310 974 625 927 498 818 558 892 262 336 161 329 388 694 156 709 16 379 466 474 99 226 200 490 606 688 187 368 584 621 352 794 223 422 573 642 779 969 30 976 393 833 349 842 391 480 130 806 243 775 105 213 446 502 703 767 351 559 552 577 221 957 489 902 2 393 706 863 17 913 542 849 23 611 146 422 181 753 230 467 638 895 57 493 318 882 221 230 764 855 523 938 237 963 299 740 243 312 134 389 205 701 129 286 11 528 69 732 457 499 386 839 470 901 166 335 108 198 525 632 194 867 635 701 278 899 148 856 324 473 447 929 88 728 673 972 189 378 490 869 726 735 107 226 343…
Output: 30

Example 2:

Input: 294 107 127 285 42 137 73 208 231 234 3 252 245 258 45 266 156 287 184 196 88 96 200 266 74 122 94 189 71 82 8 241 4 182 47 75 104 194 86 87 31 248 49 268 151 263 98 292 164 269 87 121 3 277 47 181 37 125 204 228 98 143 112 113 39 187 24 60 3 266 192 248 105 135 161 290 29 243 79 84 38 254 14 119 185 249 108 182 173 186 51 79 230 240 6 26 118 150 19 227 5 232 137 207 212 289 59 189 101 185 134 240 127 226 44 284 107 294 25 167 227 236 6 208 84 96 25 138 18 97 29 116 237 253 141 291 15 155 54 257 74 149 67 89 37 172 11 117 114 272 151 156 136 152 37 51 130 231 56 196 267 270 25 197 81 211 4 175 52 250 212 220 5 55 72 209 103 114 276 294 236 249 16 255 222 242 188 194 26 103 57 164 148 280 78 277 28 285 184 294 43 218 19 230 110 220 90 240 50 118 35 58 109 228 123 274
Output: 187

Example 3:

Input: 822 1848 565 739 13 171 31 795 164 600 767 804 403 816 582 753 106 364 216 556 34 606 35 267 574 814 265 430 375 553 49 521 89 384 3 29 330 714 33 753 269 374 81 205 315 404 23 311 195 262 187 608 420 553 172 522 638 738 32 206 334 379 452 532 38 546 376 514 252 535 135 175 39 293 605 785 151 373 530 674 139 468 309 401 23 388 229 232 325 448 60 149 186 585 526 648 409 693 346 536 164 236 59 405 133 734 268 799 505 813 123 478 360 490 137 498 1 748 750 822 213 744 400 470 85 626 89 114 210 507 242 811 187 763 106 211 624 789 316 634 271 418 152 260 428 609 238 408 1 36 13 232 116 308 595 717 310 698 93 375 4 471 341 595 235 628 412 776 559 749 674 759 284 599 647 670 202 210 234 527 244 660 158 673 119 696 35 452 343 607 78 242 33 396 244 288 149 220 372 430 113 758 416 424 289 342 12 393 …
Output: 10

Constraints:

1 <= n <= 1046; 0 <= m <= 2092; 1 <= u,v <= n.

Loading...
Test Cases:No test cases
No test cases available.
Marble routes Separate Camps - MEDIUM Coding Problem | CodeTikki