CT63187

Lysander and the Verdant corridors

MediumL6 · Pointer PhantomAcceptance: 0.0%XP: 100

Legend says the vault under the ivy courts of Vineward opens only for a perfect tally of corridors. Lysander means to find out. 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 <= 1392; 0 <= m <= 4176; 0 <= w <= 1000.

Example 1:

Input: 1102 3512 348 550 414 378 449 564 112 787 80 168 728 224 135 708 836 400 745 456 29 688 953 824 1098 11 327 893 640 4 470 977 212 370 571 901 911 900 409 686 56 8 322 412 247 605 716 201 1056 768 511 528 953 236 981 656 389 750 110 18 1004 752 126 196 949 429 693 649 139 275 248 453 574 953 427 891 736 429 887 52 210 308 307 75 455 673 161 611 377 388 745 17 261 1051 578 801 1082 532 9 598 90 769 780 782 805 941 812 46 976 221 336 843 829 173 413 963 42 786 357 1023 1053 219 749 803 929 522 854 599 25 853 920 142 287 844 50 387 870 82 796 789 87 686 127 663 786 777 274 1007 878 212 881 313 27 634 569 326 444 374 573 1067 198 532 588 209 824 1099 989 99 254 329 220 714 967 288 488 671 737 1055 784 294 883 806 261 461 203 769 807 467 117 957 586 268 523 515 273 920 874 365 860 362 83 582 682…
Output: 195980

Example 2:

Input: 720 3088 248 615 414 54 435 341 219 685 230 378 673 488 78 203 807 447 530 52 92 156 935 446 553 120 41 92 810 277 495 39 381 634 816 289 663 826 237 367 52 486 610 65 117 243 975 146 476 238 226 264 154 367 588 507 288 524 868 172 490 990 146 624 288 402 674 874 296 423 950 157 520 520 35 657 392 86 520 885 355 719 423 422 474 28 258 688 219 51 159 198 577 611 139 64 507 201 511 566 983 417 595 310 307 549 980 77 228 159 267 667 263 302 431 73 331 608 64 145 222 408 218 295 237 49 493 185 86 550 7 78 527 510 328 390 124 85 440 523 229 602 887 3 26 20 183 401 753 21 236 975 88 505 746 16 620 749 98 307 148 102 575 346 169 216 188 490 534 280 203 695 529 511 671 222 205 698 900 79 240 407 356 566 662 143 560 187 359 701 907 179 267 264 97 482 245 333 606 519 404 705 283 488 618 457 538 678 …
Output: 103465

Example 3:

Input: 1162 3670 270 427 78 396 970 528 188 334 177 516 928 548 141 1044 584 85 479 983 215 376 237 285 1040 265 378 491 346 550 783 277 330 710 708 552 884 609 47 930 658 384 503 1 137 294 385 776 1137 231 571 1086 462 44 795 490 726 812 251 513 1041 811 380 525 190 86 705 726 499 504 597 969 1092 197 11 830 854 841 1132 496 36 737 656 581 751 330 427 600 356 150 461 662 22 733 980 534 536 465 28 978 26 333 1048 573 71 403 492 488 584 950 263 754 285 626 1048 365 157 355 653 574 836 798 428 694 848 491 965 156 421 535 741 575 1115 310 519 947 40 107 759 970 73 161 404 752 1134 617 184 983 429 357 1116 586 522 955 63 354 568 382 272 296 554 32 964 127 340 909 94 544 561 623 530 884 707 719 1156 628 87 161 711 961 994 633 157 1024 405 493 879 812 588 962 779 3 281 877 95 595 779 513 939 556 333 11…
Output: -1

Constraints:

1 <= n <= 1392; 0 <= m <= 4176; 0 <= w <= 1000.

Loading...
Test Cases:No test cases
No test cases available.
Lysander and the Verdant corridors - MEDIUM Coding Problem | CodeTikki