CT31993

The Thornveld Separate Camps

MediumL4 · Loop LordAcceptance: 0.0%XP: 35

At the acacia flats of Thornveld, Clerk records each canals 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 <= 1703; 0 <= m <= 3406; 1 <= u,v <= n.

Example 1:

Input: 160 3323 4 115 52 56 67 154 44 131 77 100 91 130 11 54 2 54 96 159 9 78 130 145 15 32 32 115 79 115 10 98 37 61 31 124 79 142 37 103 101 136 97 160 55 62 97 114 28 49 121 143 142 147 123 147 29 152 23 81 112 123 91 105 81 95 61 70 57 81 33 53 40 75 18 133 40 133 7 84 7 127 27 136 35 120 22 68 19 87 6 62 12 86 78 126 99 113 104 133 21 87 2 121 75 114 151 158 29 123 72 83 106 124 45 137 24 82 69 107 84 86 6 57 41 83 90 152 13 97 5 143 91 110 25 94 31 71 27 49 105 114 16 98 87 129 26 124 129 140 21 145 45 47 71 156 82 129 46 100 94 129 150 154 1 101 108 125 67 83 30 87 8 123 68 75 19 21 106 133 94 108 107 115 14 57 13 67 44 77 46 129 77 117 37 56 5 74 95 143 83 92 105 124 23 135 108 124 38 47 107 140 11 154 33 60 1 34 9 117 6 47 12 102 80 85 6 35 37 129 28 108 122 157 53 133 71 102 120 127 70…
Output: 1

Example 2:

Input: 1657 2637 993 1036 326 462 682 1651 505 1067 541 543 799 1412 533 855 571 720 963 1285 427 768 214 258 430 492 103 1507 73 1207 1072 1482 841 1404 993 1211 1379 1651 97 601 282 698 61 362 94 1512 698 968 151 947 270 825 148 661 221 1614 378 1341 399 465 206 845 349 446 1159 1228 786 860 532 656 100 1229 1192 1490 23 622 519 1581 494 1622 822 1079 1161 1518 1046 1327 909 1583 638 1449 19 1047 811 1270 1124 1395 118 770 528 1629 1441 1448 862 1598 27 1473 387 493 13 145 429 632 677 684 1143 1615 586 1333 99 1359 604 1334 38 1198 438 1498 215 1494 1316 1485 161 1093 736 753 267 1298 76 344 246 974 880 1085 55 1099 66 606 66 786 932 1111 132 1169 26 1316 1361 1464 832 963 205 346 433 656 245 1094 147 961 881 1241 505 758 10 126 273 1065 848 1419 193 1469 357 1338 435 678 352 727 662 1318 556 1…
Output: 68

Example 3:

Input: 1325 2367 947 981 405 938 404 534 548 612 293 1156 3 115 81 349 691 1014 217 1111 24 897 219 917 545 792 520 533 195 1223 229 695 987 1082 265 860 744 781 824 1271 123 565 1050 1296 347 1132 10 756 92 920 368 437 500 1031 638 1138 677 725 1026 1254 290 477 160 567 235 1274 480 777 628 887 613 1193 62 854 655 725 810 836 280 723 316 1112 92 859 1210 1288 187 594 914 1233 730 1043 175 1029 639 955 127 1047 39 990 51 1164 955 1003 390 969 405 676 53 721 91 816 290 1079 246 693 241 531 290 539 835 1104 335 1205 736 886 585 922 427 701 20 463 92 1303 48 983 801 830 890 1164 579 1008 574 858 611 852 779 925 511 1024 249 1319 222 499 255 702 432 959 458 1013 413 538 144 1273 822 1033 189 536 139 783 1147 1164 423 1298 123 1270 325 659 613 966 489 1165 415 1239 4 949 930 1190 217 837 413 469 266 2…
Output: 43

Constraints:

1 <= n <= 1703; 0 <= m <= 3406; 1 <= u,v <= n.

Loading...
Test Cases:No test cases
No test cases available.
The Thornveld Separate Camps - MEDIUM Coding Problem | CodeTikki