CT41948

The Mossy routes of Rowena

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Legend says the vault under the poppy fields of Scarlet Plain opens only for a perfect tally of routes. Rowena 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 <= 1953; 0 <= m <= 3906; 1 <= u,v <= n.

Example 1:

Input: 701 1669 563 638 477 597 56 438 113 264 281 644 457 532 10 145 71 537 224 320 495 639 129 410 27 626 244 349 274 419 296 307 405 636 424 510 495 518 147 340 253 594 161 587 178 244 15 192 604 625 35 624 174 349 125 288 79 619 219 314 314 543 87 318 94 140 109 233 230 376 70 619 275 301 292 331 19 374 316 468 497 685 396 558 127 499 2 244 45 668 44 209 171 455 580 691 47 599 180 434 438 670 187 208 135 162 117 341 258 358 105 121 46 548 98 127 581 643 401 427 11 347 336 427 95 321 446 603 166 205 444 646 112 518 17 260 150 638 9 367 143 413 277 461 101 133 189 638 315 349 18 152 2 355 58 222 326 352 33 363 383 480 422 573 222 480 401 648 539 634 461 471 372 426 268 298 410 492 159 175 1 35 293 678 506 537 32 374 569 642 59 72 500 684 259 604 50 334 184 383 492 623 289 351 127 175 187 454 44…
Output: 7

Example 2:

Input: 745 10 10 381 208 584 382 542 28 698 309 710 225 601 352 713 24 426 283 306 301 667
Output: 735

Example 3:

Input: 1135 2543 103 645 886 1079 35 439 224 863 32 524 954 1017 157 932 606 650 237 476 463 546 97 972 482 745 563 750 1007 1071 38 87 117 1061 860 946 11 1023 1 688 27 758 108 666 251 700 8 650 165 801 102 964 125 722 82 805 223 491 47 1084 19 309 260 915 238 707 8 596 628 758 169 1013 66 384 63 335 899 1090 176 704 339 606 252 613 339 480 604 1116 142 719 527 707 464 947 32 812 387 845 1038 1062 293 429 95 803 225 592 178 300 55 56 468 929 204 227 856 1078 247 466 17 894 495 670 71 675 689 964 8 1071 511 950 1025 1079 241 316 91 135 811 1066 373 978 712 983 505 1044 460 689 882 1077 83 919 251 540 150 530 779 969 186 420 500 664 18 876 17 128 380 874 693 962 105 662 74 134 75 607 36 529 275 292 460 671 19 859 500 751 66 293 141 727 301 889 177 582 200 555 112 894 423 1082 227 312 328 439 31 28…
Output: 11

Constraints:

1 <= n <= 1953; 0 <= m <= 3906; 1 <= u,v <= n.

Loading...
Test Cases:No test cases
No test cases available.
The Mossy routes of Rowena - MEDIUM Coding Problem | CodeTikki