CT62640

The roads Cable Plan Puzzle

MediumL6 · Pointer PhantomAcceptance: 0.0%XP: 100

Morning light hits the bamboo terraces of Verdantstep as Ulrica unrolls the day's manifest of roads. The tally will decide the next shipment. Task: Print the minimum total weight of a spanning tree, or -1 if the graph is not connected. Input format: First line: n and m. Next m lines: u v w. Output format: Print the MST weight or -1. Constraints: 1 <= n <= 1485; 0 <= m <= 4455; 0 <= w <= 1000.

Example 1:

Input: 339 2431 83 133 20 119 124 105 230 278 575 24 145 831 129 261 778 3 317 4 186 259 544 184 242 34 8 41 712 89 103 950 170 331 846 223 225 272 20 138 80 55 226 267 20 237 296 73 251 143 55 324 111 114 164 705 166 330 513 236 316 467 29 185 225 10 125 349 37 286 484 34 179 398 202 277 535 36 258 174 221 265 157 99 104 960 288 325 24 70 97 158 1 236 690 250 269 571 243 307 867 248 294 992 32 53 151 226 264 995 26 143 837 70 149 909 179 281 237 3 188 26 83 93 733 87 278 356 18 135 885 268 327 157 70 329 376 129 255 761 159 239 786 224 316 512 2 225 254 56 141 502 201 331 267 59 163 131 52 313 472 117 183 333 13 121 933 86 171 846 3 129 72 68 320 605 32 63 959 184 243 633 19 241 72 130 304 462 262 332 295 4 308 501 44 246 778 16 286 189 10 259 87 89 285 329 158 180 786 44 321 376 18 183 317 29 3…
Output: 30588

Example 2:

Input: 417 3767 55 155 65 172 304 815 10 74 35 254 312 817 151 230 578 16 125 945 16 285 1 67 405 955 149 223 477 12 307 358 169 236 358 114 387 525 93 115 643 48 370 275 41 197 569 155 206 385 142 236 966 404 416 858 360 404 278 37 47 250 69 400 473 49 258 321 9 345 447 26 132 266 114 236 80 177 340 683 322 370 422 70 96 303 297 311 771 314 406 822 284 400 36 267 384 413 103 191 194 173 388 374 177 245 416 49 318 313 1 17 603 33 244 887 211 291 485 25 154 104 296 368 726 303 318 332 12 333 573 182 198 836 60 66 809 104 269 61 104 267 910 110 180 98 134 343 338 14 134 606 4 212 536 250 388 116 56 385 253 67 250 972 103 300 982 232 387 577 83 262 991 48 267 154 225 353 490 202 211 774 220 230 921 251 323 982 214 287 141 298 380 762 19 215 560 45 328 962 98 361 297 48 374 891 295 353 19 65 212 420 …
Output: 29111

Example 3:

Input: 1158 2025 131 348 251 7 424 64 863 942 879 560 931 475 238 1030 905 350 546 8 99 935 501 421 532 92 138 264 587 546 1072 640 94 958 816 669 806 764 799 1031 277 250 604 945 252 848 959 392 1102 79 677 875 904 630 654 819 474 831 107 122 154 308 97 784 539 545 1004 736 586 734 806 1007 1093 774 227 1065 197 702 1118 951 61 1069 244 516 1061 577 113 1006 864 581 643 14 455 711 459 662 702 580 362 470 756 138 603 328 83 647 718 787 1070 827 106 515 700 608 920 347 479 1007 684 290 1052 345 777 809 805 11 396 874 867 916 132 547 1045 78 64 468 10 510 640 432 506 1114 256 214 440 153 186 1064 36 185 777 749 183 1020 609 293 710 226 313 483 927 307 1009 443 92 151 794 76 857 683 480 828 354 69 164 80 510 598 726 830 1091 952 81 919 609 152 632 8 145 968 57 738 1077 993 185 604 938 644 661 248 21…
Output: -1

Constraints:

1 <= n <= 1485; 0 <= m <= 4455; 0 <= w <= 1000.

Loading...
Test Cases:No test cases
No test cases available.
The roads Cable Plan Puzzle - MEDIUM Coding Problem | CodeTikki