CT55923

Lara's Sterling roads

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Lara inherited the tannery at the honeycomb cliffs of Beeswick along with its curious bookkeeping system for roads. Time to make sense of it. 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 <= 1401; 0 <= m <= 2802; 1 <= u,v <= n.

Example 1:

Input: 1137 2403 432 603 299 1075 669 901 941 944 158 460 310 677 140 1055 945 1054 538 644 227 814 259 461 337 940 118 522 637 1044 127 1114 209 789 491 622 870 898 381 407 53 570 132 998 36 127 61 727 76 420 175 664 58 900 187 878 187 266 210 282 45 1048 175 1016 357 890 825 1030 358 516 665 922 570 736 329 875 423 1017 258 476 920 1019 237 496 658 1118 52 413 1051 1066 892 1104 716 810 408 796 765 976 167 986 908 1016 118 469 150 735 217 636 943 1030 335 1063 1036 1062 988 1137 826 1005 665 1124 1011 1108 260 442 373 735 11 489 182 444 160 946 335 565 929 962 632 839 833 983 152 507 49 884 141 237 389 618 51 380 139 371 25 558 462 864 29 122 324 793 737 801 631 968 142 674 110 933 85 119 132 946 77 764 858 1135 276 913 91 519 862 946 647 818 427 852 85 107 36 878 161 379 497 867 126 506 223 49…
Output: 16

Example 2:

Input: 1351 2027 552 1218 562 1104 251 299 317 684 656 1063 366 393 839 1163 491 927 221 1287 261 1168 320 444 187 962 616 1113 722 1113 768 1148 160 777 681 743 579 1241 260 643 29 267 133 799 147 536 312 1169 262 1334 240 959 228 618 480 881 659 1230 126 522 299 1051 484 545 511 854 1011 1288 1069 1264 707 860 264 850 969 1119 88 306 995 1243 441 737 157 665 237 766 502 626 249 421 717 855 90 1139 991 1232 79 103 471 1271 208 397 743 1190 224 894 538 1004 656 904 127 400 795 1182 323 829 1258 1286 269 880 218 1225 160 1225 562 586 208 897 272 801 270 827 66 1009 148 641 1014 1163 807 1323 551 995 180 257 280 821 987 1288 349 641 859 958 468 1011 31 209 774 1161 669 1079 426 507 873 1242 240 386 107 1219 20 965 570 881 153 1081 947 966 815 1326 686 1329 209 551 390 966 875 1123 648 1183 806 953 …
Output: 78

Example 3:

Input: 1286 2769 547 1017 599 914 861 975 822 1104 101 765 777 966 191 929 803 1275 34 505 650 1071 239 459 208 782 471 1273 721 855 64 691 572 792 40 1089 45 382 41 262 253 512 58 801 140 323 440 847 494 928 302 675 914 1276 705 836 625 732 482 930 189 906 331 1066 211 657 793 973 36 161 26 220 822 1069 537 1183 89 111 907 1247 673 865 408 1266 612 1015 260 738 1121 1169 462 1233 546 600 609 884 198 751 1110 1165 788 982 740 1246 107 565 235 975 1133 1243 299 683 248 595 176 235 218 532 495 896 535 1124 56 79 339 1187 886 1282 663 1152 652 1243 764 1034 58 104 57 794 115 168 219 589 246 809 1206 1214 496 938 273 553 692 801 594 1187 58 1242 575 1190 653 962 150 791 464 642 858 1128 96 716 725 936 295 727 270 527 942 1095 391 674 718 1045 420 698 1202 1250 1193 1204 912 929 589 997 144 254 800 12…
Output: 22

Constraints:

1 <= n <= 1401; 0 <= m <= 2802; 1 <= u,v <= n.

Loading...
Test Cases:No test cases
No test cases available.
Lara's Sterling roads - MEDIUM Coding Problem | CodeTikki