CT53113

The Scarlet routes of Gardener

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

At the cork grove of Barkhaven, Gardener 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 <= 3068; 0 <= m <= 6136; 1 <= u,v <= n.

Example 1:

Input: 1750 5426 253 481 150 1386 755 1350 569 700 257 1247 434 1176 550 1517 310 345 260 634 807 1212 557 1098 718 1275 1012 1234 32 482 370 730 519 1229 575 1037 426 1242 120 1200 56 1068 952 1045 1521 1550 707 1149 920 1143 1211 1747 328 958 574 1390 728 1186 838 1070 186 1698 1523 1579 563 1096 262 1273 820 1343 325 1051 338 587 552 1131 381 438 75 638 1367 1587 882 983 356 1034 190 975 506 1417 459 661 581 1303 504 905 35 179 770 1054 429 643 191 363 1547 1652 457 1295 84 249 1499 1744 1381 1485 254 950 1047 1367 653 883 436 582 66 1526 394 1260 939 976 284 1026 1226 1563 146 1015 974 1590 13 966 1015 1252 429 1094 424 503 541 1322 1214 1393 1037 1338 741 945 1574 1735 283 853 790 1749 1359 1522 635 1361 134 1031 110 985 22 1144 93 660 297 704 693 1558 1047 1296 1145 1681 664 1276 453 1089 5…
Output: 4

Example 2:

Input: 2879 4801 639 1074 311 1533 2423 2646 152 550 2431 2483 476 626 667 1645 709 1987 156 312 886 1313 351 2879 875 1627 283 2604 614 1290 484 2342 1205 1457 513 1800 2259 2393 511 2638 497 1473 1266 1689 54 1596 1692 1866 2369 2806 1706 2540 18 462 1874 2641 493 820 1097 1395 518 2658 297 1086 2496 2500 2227 2469 61 2669 1975 2119 28 30 1948 1986 851 1127 358 2543 1695 2078 1667 2610 436 2233 207 675 1388 2606 744 1223 682 2712 148 1963 544 2613 669 1169 836 1655 1523 2352 263 2347 257 893 273 533 60 1888 625 751 1070 1298 1665 1813 659 1883 1292 1321 616 1913 1603 2109 1431 2682 269 574 523 1243 397 1122 2437 2518 636 2394 97 720 1664 2866 378 1317 1572 2227 827 2506 861 1413 2470 2732 276 1665 2033 2781 1018 1082 1297 2448 176 2551 1343 1734 1659 2010 1519 1746 754 1755 481 1498 6 2297 1585…
Output: 110

Example 3:

Input: 911 1243 472 739 109 253 333 784 140 291 417 512 30 231 685 840 340 539 148 868 792 878 86 523 25 48 637 868 69 812 509 515 132 415 246 526 4 15 23 294 294 901 336 904 132 902 95 553 147 450 412 420 840 900 71 466 174 751 123 548 106 181 24 854 18 656 73 348 205 895 441 444 291 693 730 836 59 85 140 521 319 793 79 788 323 509 286 503 205 429 60 380 221 374 225 241 298 619 323 682 239 715 517 867 146 262 247 686 37 351 164 188 168 494 586 709 302 904 186 868 102 434 526 741 91 858 112 854 231 392 464 835 678 735 499 513 8 633 427 475 223 226 257 364 106 759 412 689 577 898 387 732 415 768 664 692 28 615 199 861 599 814 112 182 176 243 695 883 14 868 18 621 665 910 422 828 1 289 800 802 93 682 133 881 108 294 341 451 81 134 473 874 343 790 833 855 549 666 351 478 401 670 87 673 396 885 3 613…
Output: 62

Constraints:

1 <= n <= 3068; 0 <= m <= 6136; 1 <= u,v <= n.

Loading...
Test Cases:No test cases
No test cases available.