CT53145

Axel Counts the canals

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Legend says the vault under the lakeside town of Mirrormere opens only for a perfect tally of canals. Axel 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 <= 1784; 0 <= m <= 3568; 1 <= u,v <= n.

Example 1:

Input: 1022 2783 646 848 523 603 413 469 68 276 818 950 346 591 99 825 338 529 557 661 50 709 23 898 246 951 156 232 398 900 465 872 809 815 296 756 281 738 228 595 238 646 295 732 393 778 838 848 815 858 69 991 363 924 330 748 379 552 28 550 180 472 686 972 575 751 188 503 401 773 80 926 447 1020 356 975 303 647 98 501 549 789 208 796 307 321 85 954 77 154 498 765 467 535 61 682 828 951 170 480 725 956 320 770 606 724 331 746 511 663 366 782 821 915 401 753 252 476 451 660 257 383 367 669 412 735 559 837 6 614 26 816 321 425 221 412 87 464 326 999 152 867 76 385 359 778 7 364 85 985 170 377 813 868 305 680 177 875 71 288 107 1022 482 726 640 741 796 990 41 232 200 975 20 822 172 864 30 712 279 865 97 1002 75 896 72 651 224 870 134 333 365 943 585 814 659 774 548 560 378 559 168 185 315 935 53 61…
Output: 4

Example 2:

Input: 1211 3017 372 728 164 267 260 1024 429 1133 423 1115 116 356 32 490 293 781 598 985 394 440 521 992 461 909 597 792 409 514 684 1006 147 618 190 1011 265 299 17 482 318 469 846 981 495 557 134 158 250 550 443 478 501 1204 462 827 184 1197 652 1074 361 1098 770 1044 149 613 152 180 251 646 434 737 811 890 194 641 132 489 13 706 68 283 572 931 236 540 268 567 719 1072 925 1174 41 1131 533 1081 440 496 261 456 561 1163 727 799 580 795 1047 1152 173 384 608 947 33 507 932 1146 102 246 799 835 926 1025 412 838 370 426 148 783 411 451 254 816 588 792 241 493 743 1093 347 993 243 875 261 670 28 169 682 1086 208 310 992 993 271 969 800 989 205 1114 660 1196 441 948 345 547 169 544 58 482 106 1144 200 232 418 980 62 690 1074 1204 200 1099 407 1104 990 1181 123 1042 433 1192 608 1120 494 552 36 1005…
Output: 17

Example 3:

Input: 1555 1641 644 1415 275 666 52 681 255 1298 234 1121 855 1278 1260 1372 146 955 219 327 95 463 824 911 111 190 16 413 734 1484 16 380 920 1327 268 1367 866 1551 871 1070 188 1510 711 806 636 685 114 487 529 764 40 99 599 1512 1305 1524 867 1303 602 783 1105 1193 1134 1428 183 1155 701 1209 874 1111 662 1076 124 666 519 1183 1243 1456 368 570 372 655 133 458 493 1324 449 1119 726 1419 432 1365 1384 1481 533 926 107 1417 779 1229 188 695 251 707 607 739 108 1178 159 834 343 611 256 506 63 496 514 1381 918 995 345 388 802 843 722 831 1211 1445 1166 1393 269 1240 561 1364 1397 1511 298 625 189 1527 619 811 806 1436 950 1539 313 725 135 739 974 1463 13 1095 319 629 985 1268 889 1353 797 1095 439 1197 50 701 445 782 890 1019 257 1519 290 740 372 1234 461 1524 651 960 325 339 915 1004 409 853 82 1…
Output: 232

Constraints:

1 <= n <= 1784; 0 <= m <= 3568; 1 <= u,v <= n.

Loading...
Test Cases:No test cases
No test cases available.
Axel Counts the canals - MEDIUM Coding Problem | CodeTikki