CT37190

Vani's Ledger of routes

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Deep in the caldera rim of Firewatch, Vani studies rows of routes entries. One clean number will settle the guild's oldest argument. 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 <= 1478; 0 <= m <= 2956; 1 <= u,v <= n.

Example 1:

Input: 128 1652 78 124 9 18 20 38 12 58 24 121 79 97 43 94 94 124 49 121 8 67 79 109 77 102 64 107 4 117 24 46 84 94 64 128 23 31 19 45 27 103 50 123 73 111 62 70 74 84 85 112 52 53 41 55 25 43 30 122 48 83 65 74 121 126 103 107 37 82 34 119 22 79 55 76 41 119 66 123 91 119 18 85 25 32 18 56 7 40 63 92 75 94 9 22 50 71 20 87 41 56 29 103 16 75 76 95 31 86 11 86 78 115 100 125 40 57 52 54 6 108 53 80 7 54 79 116 63 118 1 82 3 59 117 128 9 84 82 112 32 128 33 63 59 96 75 84 8 92 5 115 43 125 33 77 82 108 58 100 4 103 43 50 1 4 17 128 11 40 25 53 20 101 65 121 89 103 5 99 50 53 5 95 95 99 25 82 19 77 67 114 15 90 58 124 18 43 16 19 27 69 55 107 91 105 33 100 14 128 15 17 62 73 68 113 53 69 34 70 7 82 44 110 21 80 86 91 57 103 31 61 13 100 21 86 18 38 56 115 68 80 62 104 69 88 27 119 44 93 25 87 40 7…
Output: 1

Example 2:

Input: 1201 2174 745 1132 267 764 3 1078 238 774 37 589 229 1020 473 527 148 724 406 767 742 805 99 989 388 1046 718 1083 477 539 219 430 73 946 302 814 823 890 623 901 502 538 132 760 671 1165 501 1178 97 546 887 953 67 673 385 540 966 1104 177 461 94 1094 131 913 909 961 531 1038 516 945 425 613 772 814 480 1030 505 936 621 1118 551 1051 455 523 276 851 141 1128 316 630 193 250 252 1169 900 1158 27 30 220 240 178 856 167 242 170 394 381 1065 29 995 433 688 159 938 252 407 51 454 458 1055 52 672 328 921 239 768 437 1068 792 1170 149 449 5 785 486 882 269 711 276 677 618 1198 439 631 653 1053 727 728 775 868 504 664 597 1089 99 1075 512 941 79 1178 583 721 845 1027 677 1196 276 1122 353 818 435 618 173 654 616 1064 252 276 341 379 499 932 694 988 362 834 805 989 337 860 18 287 77 196 54 438 136 7…
Output: 36

Example 3:

Input: 1473 2381 784 1468 61 471 57 1282 41 1269 1176 1435 945 1306 763 778 33 248 172 499 923 1255 166 401 1088 1369 20 772 357 1361 2 564 133 1268 838 848 710 1438 431 1168 571 646 108 841 431 1221 155 676 752 762 73 375 356 1127 457 1262 597 1339 488 1007 361 590 661 896 41 474 66 1312 704 1386 353 1326 810 1156 169 1406 78 236 450 925 406 1363 620 870 116 415 291 1195 487 684 218 915 23 1134 369 1251 641 1440 554 632 740 1164 1028 1377 716 1427 88 605 19 134 164 348 62 1241 387 1115 130 791 586 1410 172 532 744 1257 131 814 616 1438 52 941 1119 1460 710 1257 214 328 148 1095 1283 1372 979 1437 693 946 338 1070 992 1085 756 1259 355 1409 546 872 273 1374 360 1155 936 1012 681 712 84 205 214 1433 751 830 1354 1453 564 1352 381 497 103 1275 577 621 650 1232 242 975 371 1016 196 424 1223 1294 33 …
Output: 59

Constraints:

1 <= n <= 1478; 0 <= m <= 2956; 1 <= u,v <= n.

Loading...
Test Cases:No test cases
No test cases available.
Vani's Ledger of routes - MEDIUM Coding Problem | CodeTikki