CT35582

The Frosted tunnels of Hema

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Every season at the cork grove of Barkhaven, someone must secure the caravan contract. This year the task falls to Hema, armed only with the tunnels register. 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 <= 2565; 0 <= m <= 5130; 1 <= u,v <= n.

Example 1:

Input: 657 3226 1 455 63 408 398 617 197 265 125 626 359 402 42 420 2 350 277 417 219 601 27 202 165 378 61 592 183 560 300 561 105 139 184 202 512 628 75 322 142 219 46 545 116 176 202 631 153 331 86 344 394 404 13 110 96 584 153 275 224 475 283 285 64 380 315 610 472 506 25 577 476 557 339 479 54 179 32 635 203 462 101 572 162 564 102 237 334 448 287 290 147 325 401 434 8 64 105 199 84 457 2 116 60 217 191 389 153 168 300 324 29 67 177 614 141 207 462 559 357 636 429 655 159 582 134 268 277 302 175 630 207 626 428 611 113 315 194 371 136 326 282 619 240 475 58 655 84 590 95 318 231 331 3 360 195 310 594 629 133 290 143 175 132 379 16 257 264 646 68 606 94 172 63 348 384 468 197 214 315 409 52 199 207 336 63 145 587 601 190 620 471 518 126 422 485 544 1 592 381 386 131 504 106 556 372 558 124 28…
Output: 1

Example 2:

Input: 714 104 53 651 347 572 362 435 191 197 281 484 336 486 191 332 180 525 305 456 326 407 618 627 290 529 345 593 188 421 8 518 532 602 602 678 113 621 24 431 472 618 36 368 50 324 25 230 410 546 42 86 416 687 194 356 563 599 175 258 12 265 49 541 85 448 246 532 6 35 179 238 11 408 551 686 126 388 404 635 281 713 153 245 108 229 523 588 19 352 216 692 165 452 332 447 164 541 135 451 203 451 49 112 269 499 242 671 39 615 13 202 50 183 355 713 246 411 212 338 332 694 458 505 257 524 46 625 176 369 79 708 266 349 365 589 113 712 144 179 24 241 122 405 27 714 133 681 308 404 50 646 434 558 144 278 162 524 354 610 271 464 58 679 4 492 393 604 442 632 242 581 147 178 106 207 24 256 6 22 19 265 425 441 33 153 42 460 127 604 57 284 114 474 126 286 80 687 74 141 157 567 211 552 98 279 304 562 310 697
Output: 610

Example 3:

Input: 105 4260 4 94 101 105 77 93 2 8 37 100 36 92 68 74 29 30 10 36 44 45 77 103 18 90 59 69 52 71 71 72 13 57 6 97 40 105 16 75 15 30 57 105 69 76 50 83 59 78 8 82 47 56 90 94 45 47 81 103 37 65 77 102 15 19 29 63 9 75 31 90 33 37 25 81 3 10 41 67 63 86 48 51 17 22 56 78 78 84 6 31 60 99 20 56 57 99 44 67 66 72 87 90 61 86 38 73 20 25 31 60 8 95 24 40 74 89 18 60 1 38 26 37 29 53 49 59 37 101 4 52 84 93 19 20 12 20 5 80 16 52 12 84 13 90 53 78 80 86 9 36 36 59 60 68 54 87 79 87 14 53 78 81 7 39 33 82 23 97 36 53 18 87 23 84 67 70 18 68 13 79 20 96 66 99 70 73 51 68 74 104 15 48 48 79 4 80 34 70 50 93 1 97 40 103 2 47 11 55 77 97 43 80 15 66 84 88 16 29 8 103 5 89 76 80 39 61 56 67 1 58 33 72 25 55 76 100 3 7 45 92 27 58 47 82 27 75 58 74 78 104 14 82 1 99 7 45 14 15 6 15 83 87 44 86 50 97 74 7…
Output: 1

Constraints:

1 <= n <= 2565; 0 <= m <= 5130; 1 <= u,v <= n.

Loading...
Test Cases:No test cases
No test cases available.
The Frosted tunnels of Hema - MEDIUM Coding Problem | CodeTikki