CT52485

Fiora's roads Separate Camps

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Fiora found an old ledger of roads in the kiln attic at the clockwork quarter of Gearford. The margin notes pose a precise question. 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 <= 1336; 0 <= m <= 2672; 1 <= u,v <= n.

Example 1:

Input: 851 1675 2 140 85 515 144 534 451 614 58 395 297 501 305 414 558 583 664 671 9 753 33 304 355 759 338 379 468 734 199 665 517 664 672 745 659 748 134 673 346 803 235 362 341 504 688 845 298 443 296 745 33 242 39 392 533 823 332 678 656 669 437 759 183 673 211 577 209 391 26 28 84 245 146 216 439 607 186 602 160 274 601 750 167 573 78 649 455 529 587 719 36 593 277 622 246 695 688 837 259 466 448 826 104 592 649 689 154 385 354 766 44 606 209 649 430 493 3 157 126 792 120 541 221 447 511 572 378 769 378 674 340 789 298 771 577 617 267 774 178 413 580 846 26 250 3 256 206 276 591 612 578 768 310 794 694 829 364 752 408 776 215 467 144 399 16 430 277 811 223 336 100 691 24 123 609 757 194 234 586 599 77 545 425 818 605 631 150 430 391 699 806 809 597 720 392 494 422 605 322 560 330 339 74 689…
Output: 20

Example 2:

Input: 669 363 1 222 44 117 361 563 237 355 556 561 45 466 340 423 50 242 142 479 515 621 505 647 376 538 10 112 21 508 460 470 76 460 416 603 64 233 98 628 334 554 486 626 550 629 198 405 50 355 45 201 40 650 63 635 311 572 266 359 151 206 165 397 99 135 133 645 213 579 55 486 398 637 187 306 21 309 156 402 156 508 90 160 71 268 196 269 185 314 185 266 234 651 335 619 96 285 199 256 522 653 477 520 173 227 191 606 89 442 122 582 458 467 172 474 363 508 94 326 156 442 252 347 247 280 119 374 84 102 38 315 64 397 232 373 22 102 132 192 187 225 235 539 181 264 193 460 400 524 221 397 72 367 256 297 219 562 394 400 308 647 272 499 460 594 177 409 133 312 280 445 212 345 4 423 328 380 109 307 143 328 45 244 78 324 409 442 304 322 90 664 401 482 169 558 132 545 37 66 188 367 349 411 148 484 558 644 14…
Output: 308

Example 3:

Input: 1258 2107 596 928 230 1016 364 790 1075 1202 27 1213 748 1054 321 822 353 567 141 850 43 44 143 405 564 904 1120 1180 481 781 109 956 122 558 626 893 197 819 375 950 92 618 436 638 119 281 420 1225 598 1046 212 1130 166 1179 112 231 223 968 64 177 763 919 421 878 703 923 235 514 641 1012 17 359 1077 1258 449 1068 49 959 50 923 255 585 44 841 224 799 73 1184 101 1069 259 739 842 1151 345 532 868 1247 448 526 783 1149 357 391 831 1236 52 1217 611 782 439 446 733 1247 430 614 287 469 194 1045 217 388 117 516 1085 1127 400 594 75 232 326 677 31 861 28 142 174 240 181 581 69 677 401 1236 420 679 918 1146 101 213 288 657 999 1248 127 1209 784 843 612 1123 791 940 837 1028 800 1255 26 521 133 598 383 1018 1042 1187 739 844 399 1225 195 686 617 857 14 587 316 729 66 308 524 698 142 1010 109 270 58…
Output: 45

Constraints:

1 <= n <= 1336; 0 <= m <= 2672; 1 <= u,v <= n.

Loading...
Test Cases:No test cases
No test cases available.
Fiora's roads Separate Camps - MEDIUM Coding Problem | CodeTikki