CT58830

The Driftwood Cable Plan

MediumL6 · Pointer PhantomAcceptance: 0.0%XP: 100

The dispatch writer Botanist has been asked to recover the missing manifest. On the desk lies a long table of canals readings. 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 <= 1803; 0 <= m <= 5409; 0 <= w <= 1000.

Example 1:

Input: 924 4425 234 556 194 199 790 369 683 836 729 115 403 168 82 839 177 117 747 38 480 527 748 279 437 872 52 914 350 158 678 464 277 821 387 35 91 600 288 890 529 468 474 191 327 684 517 49 129 599 110 563 683 742 749 849 199 533 93 172 738 474 295 879 154 463 501 147 578 819 442 44 481 564 272 780 754 100 910 971 410 717 716 269 690 367 101 338 379 15 668 357 108 711 198 165 239 609 391 818 529 316 464 177 339 724 539 790 824 846 356 835 415 199 240 175 146 270 932 626 844 936 87 100 270 809 865 450 500 859 781 28 660 573 314 751 201 673 748 328 497 498 1 176 267 170 805 844 496 29 620 538 300 699 646 269 739 226 45 732 959 638 905 800 134 516 344 86 441 834 81 784 560 672 743 534 178 576 411 343 439 347 659 854 241 62 156 360 235 820 8 705 809 189 437 626 66 435 609 33 99 367 883 53 739 609…
Output: 117677

Example 2:

Input: 827 3592 121 430 665 568 619 465 95 646 396 45 232 153 415 515 629 57 63 369 102 157 367 451 753 120 227 800 54 171 565 631 332 729 493 595 788 476 155 208 753 47 600 664 737 812 33 43 202 905 391 771 950 313 621 928 7 427 1 252 479 780 558 675 713 186 623 508 229 716 698 208 462 79 399 691 892 112 384 561 34 281 634 617 688 711 488 655 374 40 821 981 238 768 584 375 800 250 261 297 222 741 753 779 5 791 448 113 609 985 312 730 134 327 810 680 252 716 307 206 476 794 588 823 400 148 229 717 457 775 699 168 827 877 400 701 227 23 644 837 190 810 956 664 680 378 373 781 98 204 765 558 479 681 857 424 558 775 251 761 33 391 617 902 611 770 380 69 395 841 288 413 803 700 702 216 257 480 379 136 137 206 546 731 334 191 624 402 25 364 549 22 575 749 110 287 752 668 776 484 75 137 359 257 784 298…
Output: 112601

Example 3:

Input: 598 2417 241 388 5 110 205 486 226 373 31 245 444 451 25 218 307 34 525 969 73 527 140 183 246 90 103 277 334 339 557 507 270 429 607 491 514 69 67 125 696 399 504 942 72 236 77 238 565 950 334 513 558 2 494 35 289 443 63 275 442 823 173 356 181 41 302 632 58 320 995 111 226 847 469 475 287 141 305 693 72 493 491 267 540 814 245 314 254 74 523 999 132 144 988 97 192 254 409 410 745 489 541 436 263 383 974 117 565 52 127 532 794 270 492 146 484 577 791 513 589 350 175 478 669 424 493 921 180 450 634 126 516 892 259 395 306 126 530 993 388 405 998 241 246 359 328 415 612 10 178 512 29 246 605 223 464 596 204 507 575 2 165 382 365 481 740 13 176 304 62 213 148 56 88 42 337 465 209 51 99 724 396 480 324 305 375 163 408 483 925 317 400 718 169 348 338 442 576 746 315 458 896 129 576 30 276 447 …
Output: 87707

Constraints:

1 <= n <= 1803; 0 <= m <= 5409; 0 <= w <= 1000.

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