CT59403

The roads Cable Plan Puzzle

MediumL6 · Pointer PhantomAcceptance: 0.0%XP: 100

The harbor bell rings at the island market of Coralcove; Quinn weighs the day's roads manifests and starts the calculations. 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 <= 1093; 0 <= m <= 3279; 0 <= w <= 1000000.

Example 1:

Input: 507 2025 151 191 915733 135 221 330730 293 326 756697 20 101 531376 219 372 873441 138 451 365358 6 120 459206 13 338 979722 185 250 767011 62 455 438982 175 342 777459 170 300 802606 238 264 220850 187 467 869923 270 346 417911 4 453 949849 27 168 154020 59 176 975200 354 478 402689 29 505 356122 187 299 435493 182 296 351074 12 394 999666 16 179 421232 9 60 644923 51 410 303630 371 452 740107 33 254 853551 303 356 632136 201 506 142243 91 250 100216 202 370 432980 19 430 950703 72 316 251920 21 229 735562 257 261 689763 114 498 616047 240 303 152267 319 367 528427 150 228 490336 280 339 103072 176 474 365717 272 478 269412 38 242 275411 34 153 942252 88 242 869744 184 292 135686 125 317 949514 93 475 104263 175 471 930237 3 420 481040 182 195 374853 348 447 485516 308 454 167744 259 307 …
Output: 72760388

Example 2:

Input: 671 2184 299 392 892074 32 534 423191 414 628 202294 367 637 892937 245 547 261840 88 571 677743 236 613 266600 218 669 967205 327 385 886750 16 374 325697 163 291 101798 423 488 149977 11 474 886050 77 492 568340 370 547 451828 245 313 676627 144 350 317643 406 593 648700 42 246 954548 171 326 933193 5 391 134863 70 360 365147 23 126 225526 116 349 551181 128 504 341988 59 280 19217 33 112 260648 76 553 157386 395 424 208145 426 560 631501 184 485 751325 334 358 885883 109 627 440238 140 522 884944 428 434 801941 14 141 255776 588 658 902954 376 396 370885 48 344 513292 531 598 958193 503 573 165097 332 416 892132 199 262 541068 83 638 922127 428 450 858177 176 512 592742 29 354 159485 191 394 847736 13 116 742227 118 558 183658 568 586 161210 395 585 832753 406 435 371260 34 531 70595 95…
Output: -1

Example 3:

Input: 1003 2427 57 371 832788 201 497 206677 504 736 453065 323 387 303585 33 106 377380 557 666 767318 111 485 353749 101 608 122171 451 864 452805 518 663 153403 424 736 490753 493 863 949259 25 476 376901 310 993 1717 214 631 53903 897 981 145417 272 761 888735 481 878 279015 27 87 832735 682 958 453928 163 934 658482 420 792 524562 309 438 377211 202 277 410205 731 927 513974 522 623 13274 318 518 680138 453 745 253010 64 608 475580 817 947 67392 599 843 932775 698 800 811646 416 812 810805 870 945 331503 207 817 301067 735 947 74840 265 834 576680 17 559 810313 530 1001 725205 744 997 947 462 976 369011 266 640 705384 331 750 67304 215 667 15880 484 830 578333 313 976 96959 105 838 933355 329 659 631268 273 885 417497 209 324 526761 527 934 415828 132 715 891167 45 738 611408 266 363 102716…
Output: -1

Constraints:

1 <= n <= 1093; 0 <= m <= 3279; 0 <= w <= 1000000.

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