CT62025

The Violet routes of Nandini

MediumL6 · Pointer PhantomAcceptance: 0.0%XP: 100

Nandini the customs officer watches over the mangrove channels of Rootwater's stores of routes. A careful computation stands between order and chaos. 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 <= 1740; 0 <= m <= 5220; 0 <= w <= 1000.

Example 1:

Input: 703 1458 324 616 887 600 630 236 30 653 183 71 223 930 219 595 578 288 648 574 56 672 38 225 552 511 98 119 245 52 53 731 239 464 655 33 367 190 360 541 154 119 326 967 55 154 820 16 677 963 88 524 511 246 387 516 135 665 843 389 678 359 169 475 62 369 602 982 104 277 639 62 618 295 221 402 697 348 428 380 307 406 385 92 162 68 157 236 170 27 519 648 385 701 900 4 529 867 287 506 881 487 703 527 40 569 204 74 92 105 271 401 595 174 577 123 60 479 665 345 540 962 529 698 25 237 269 382 8 577 646 71 460 792 135 523 666 220 674 521 296 643 297 215 474 963 278 581 344 21 418 455 128 322 859 435 596 371 486 574 331 419 651 997 353 360 442 522 563 67 142 526 655 127 554 947 175 570 66 353 436 565 350 654 476 95 192 850 230 512 783 28 516 65 654 696 17 262 627 651 199 601 497 227 703 588 332 463 …
Output: 193519

Example 2:

Input: 1272 3572 385 945 239 783 901 19 547 932 237 17 753 717 866 1260 704 528 978 830 600 820 342 554 1042 15 439 820 167 847 1141 986 508 1202 783 31 853 195 858 985 76 179 1006 922 315 664 711 656 1062 850 786 1170 451 726 827 19 432 556 355 419 823 762 366 958 337 615 1269 798 320 839 400 1105 1135 359 414 853 441 603 1015 454 488 1072 756 660 1054 390 354 405 530 257 893 396 95 318 862 527 900 266 467 691 995 112 862 101 290 873 386 264 876 409 431 1135 885 485 1007 456 158 312 55 1037 1192 635 218 420 7 735 967 74 751 1132 38 468 568 656 47 858 356 31 100 400 111 707 791 28 459 458 445 841 1000 206 586 400 708 1191 725 330 1134 499 344 1229 512 890 1158 852 107 402 857 154 497 727 1066 1153 931 627 879 33 19 1036 367 766 1184 614 405 860 210 1256 1265 771 296 406 833 1022 1270 336 1117 116…
Output: 258323

Example 3:

Input: 618 4729 101 297 675 252 544 767 317 522 790 130 168 789 205 225 500 178 220 821 310 431 165 229 452 667 491 492 32 196 401 484 283 358 665 374 552 536 271 511 983 142 376 328 337 499 925 89 296 997 256 501 825 371 458 330 99 505 8 475 605 915 85 254 427 249 451 686 155 536 288 530 599 317 167 213 833 95 529 754 12 434 631 82 509 297 57 85 436 370 616 257 443 448 751 219 457 558 418 465 628 153 420 819 28 259 254 243 617 481 375 440 915 37 218 425 147 555 764 92 464 233 146 364 425 88 319 871 209 254 966 86 532 638 24 544 265 216 254 953 145 568 251 1 321 474 119 419 839 23 428 116 30 281 586 123 589 113 238 308 134 416 421 81 223 391 29 91 363 836 13 260 847 285 298 930 238 526 767 498 512 960 463 557 972 144 501 690 429 447 622 342 503 750 327 344 575 189 311 604 185 313 423 5 253 55 268…
Output: 50109

Constraints:

1 <= n <= 1740; 0 <= m <= 5220; 0 <= w <= 1000.

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