CT62157

Draper's Cable Plan Ledger

MediumL6 · Pointer PhantomAcceptance: 0.0%XP: 100

In the mountain city of Highreach, Draper the surveyor keeps careful count of the routes. Restore an old family record, every figure matters. 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 <= 945; 0 <= m <= 2835; 0 <= w <= 1000000.

Example 1:

Input: 899 1288 180 354 308492 206 434 56646 458 476 890271 5 370 738512 62 584 74346 129 223 780554 295 677 198718 276 371 493354 528 792 739809 51 656 139664 86 531 14176 199 667 272123 404 563 554831 37 229 804279 616 635 652747 166 664 452452 255 534 73920 87 233 199353 381 783 578601 487 680 16604 517 632 630526 190 779 814182 341 623 672707 457 804 12832 260 857 960852 106 442 731241 69 486 559457 643 674 466219 321 513 296034 250 798 892407 254 457 238285 284 553 388039 304 441 881457 16 728 154186 69 543 616894 471 723 560410 336 516 695995 357 503 368812 616 642 282771 457 522 429736 55 508 120904 824 859 919108 310 879 506649 433 889 894762 28 145 599538 271 793 829826 90 694 180996 218 424 537116 422 814 375466 153 858 44103 234 544 411395 124 731 301011 25 818 422354 14 516 714487 675…
Output: -1

Example 2:

Input: 627 2452 62 473 898254 441 558 667231 167 282 798766 499 510 361265 158 505 372843 83 474 87605 55 154 584308 36 240 454323 67 537 757365 149 474 705801 244 270 660506 212 547 160329 20 251 473456 242 417 774764 419 535 550875 343 578 117920 346 579 608118 446 603 151097 19 128 888340 198 557 516808 35 544 602605 527 594 132067 169 264 696618 53 173 692236 114 211 444624 133 275 944984 31 625 728148 66 560 118090 306 396 866395 140 308 411032 36 620 150741 121 228 717307 63 438 748635 441 491 354780 232 355 559434 61 580 494051 574 626 44364 76 350 996189 228 530 398893 143 261 459195 14 427 253842 10 379 11087 52 104 505219 175 262 78093 421 598 145415 248 435 608318 175 493 758109 291 398 135717 87 113 515008 42 198 443481 317 508 9970 339 519 393700 138 451 288408 150 576 142485 75 77 4…
Output: 95902009

Example 3:

Input: 881 2644 382 765 919404 485 691 965794 492 587 800429 270 524 650351 825 850 325928 362 593 511168 194 588 949596 609 695 156738 98 201 500973 155 212 227284 396 432 195044 201 571 159912 521 847 375199 124 208 151653 334 592 330259 15 228 898775 437 494 487561 322 446 597651 186 624 36851 139 827 573758 96 707 513845 45 467 697270 333 459 374875 129 637 558445 14 375 403824 154 375 395376 157 748 536440 289 754 459539 71 260 589057 711 802 809901 11 92 558870 178 470 408183 502 762 174582 568 689 703796 126 420 782392 427 682 168162 443 521 272181 103 257 274126 573 858 518392 223 737 789978 383 689 23367 501 781 683230 367 578 427870 706 835 179877 361 466 136502 563 617 962641 443 666 429928 72 725 934299 98 307 389885 38 423 46778 4 807 651612 175 527 100377 316 698 12185 195 259 84142…
Output: -1

Constraints:

1 <= n <= 945; 0 <= m <= 2835; 0 <= w <= 1000000.

Loading...
Test Cases:No test cases
No test cases available.