CT59479

Golden tunnels Cable Plan

MediumL6 · Pointer PhantomAcceptance: 0.0%XP: 100

Morning light hits the salt flats of Palemere as Vera unrolls the day's manifest of tunnels. 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 <= 1261; 0 <= m <= 3783; 0 <= w <= 1000000.

Example 1:

Input: 1225 3539 272 494 507725 254 514 475423 88 1044 961557 424 960 203935 963 1024 881923 230 612 105524 204 775 15495 233 696 374559 950 1147 357957 422 813 185686 257 512 338967 445 686 262799 464 736 753139 877 1054 216381 693 1123 616357 681 705 949871 354 872 978631 458 1222 4111 722 948 24046 767 1156 951421 514 858 955254 586 598 32772 67 993 706494 458 611 196703 192 919 487767 26 102 722249 647 725 442597 620 635 276505 180 1029 460247 56 1085 869826 689 1076 482475 145 654 970553 211 285 600065 688 1097 444839 419 1081 91206 369 643 170180 260 895 142900 610 657 44539 124 954 6816 35 505 623644 612 883 802408 159 743 794662 172 688 747581 72 125 891725 740 1165 319001 353 480 166568 917 1150 92902 568 602 275416 309 414 465629 694 1031 873892 1105 1219 401144 535 1074 241133 590 783 …
Output: -1

Example 2:

Input: 259 1265 27 37 991584 136 254 181600 80 154 43702 136 225 862837 134 208 647192 124 166 503782 108 168 593492 121 128 922302 38 71 76847 17 110 921842 54 92 181168 31 84 9131 122 176 344741 107 150 642635 133 189 983142 202 221 927453 105 209 160393 179 190 904244 125 186 361989 23 132 114789 66 209 745779 70 114 916710 3 13 144316 139 201 957830 58 116 843992 137 182 940075 37 244 268545 27 194 278454 138 196 22302 147 184 239820 181 252 108433 72 196 594960 1 134 644703 36 74 905685 9 170 445409 101 207 602352 56 183 592394 179 222 66491 20 94 223209 8 53 377954 29 59 139153 9 216 440671 156 164 293803 133 177 963479 12 214 617227 53 83 96528 82 106 787543 58 121 169313 17 151 781993 68 232 230493 86 202 772122 150 247 911373 99 210 509709 110 252 628700 69 151 258859 105 186 78936 197 2…
Output: 31127513

Example 3:

Input: 567 1157 139 424 675343 458 495 526977 383 405 778627 88 339 814130 50 433 782255 394 400 550732 66 487 963150 132 419 694992 177 211 131854 342 491 598119 164 323 715585 528 547 27470 124 477 381189 86 150 188649 16 397 92088 285 365 207000 157 558 227518 102 272 819728 79 134 951522 180 212 515153 88 349 104609 385 457 268911 447 545 328833 478 513 751925 36 417 108309 14 125 132544 358 446 618968 195 388 918701 47 160 865817 79 559 786670 42 133 10256 211 298 798038 8 245 381146 32 480 444026 280 350 848432 189 483 185713 230 326 39419 242 451 629906 361 407 721744 208 411 236417 18 509 835534 356 475 168937 102 358 821246 191 448 684225 252 269 25600 54 473 481122 122 451 520592 64 210 486220 242 316 394845 253 419 840546 279 363 232217 415 431 134519 339 413 979206 51 83 200531 416 55…
Output: -1

Constraints:

1 <= n <= 1261; 0 <= m <= 3783; 0 <= w <= 1000000.

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