CT57221

Rohan's Cable Plan Ledger

MediumL6 · Pointer PhantomAcceptance: 0.0%XP: 100

Caravans arrive at the lantern district of Glowfen with crates of routes, and Rohan the quartermaster must account for every last one. 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 <= 1142; 0 <= m <= 3426; 0 <= w <= 1000.

Example 1:

Input: 872 1886 749 755 642 39 124 944 657 734 7 586 615 82 355 444 864 310 446 76 351 656 932 280 518 786 186 236 636 396 813 980 49 334 168 302 481 58 540 817 115 341 507 927 67 545 811 390 820 933 133 338 309 89 224 670 517 755 923 237 615 424 113 836 222 22 817 12 135 720 626 168 510 41 420 617 499 835 848 605 5 585 349 390 862 321 412 672 173 288 814 794 94 480 267 22 516 975 597 620 925 356 739 768 446 564 512 41 574 29 175 358 968 815 825 427 350 690 335 32 307 244 359 376 760 89 218 169 52 466 943 307 649 175 272 477 930 182 538 922 30 131 975 58 157 965 539 706 369 323 821 774 16 193 932 276 720 722 259 768 889 58 819 71 161 689 271 672 829 997 553 706 329 458 721 33 454 611 257 495 846 137 69 566 149 91 449 543 320 428 931 114 298 273 471 723 653 412 503 559 148 255 397 682 719 504 175 …
Output: -1

Example 2:

Input: 611 1738 144 590 89 21 216 562 231 465 1 129 210 644 92 136 748 291 561 388 264 384 499 25 493 379 187 460 903 152 408 486 17 277 128 260 497 206 418 598 305 347 459 174 166 452 759 116 238 529 221 329 568 359 384 28 224 289 918 50 447 297 478 598 903 370 553 44 31 442 433 87 586 468 22 133 219 387 398 262 98 323 171 223 406 637 171 246 765 107 417 221 36 273 6 66 551 186 240 549 262 515 541 96 185 551 82 34 52 71 55 581 799 47 482 65 285 601 5 124 422 557 90 354 330 441 568 534 137 566 52 217 514 715 254 426 493 301 452 677 43 512 852 186 464 33 339 378 715 88 491 694 292 404 822 207 609 837 126 356 303 412 567 473 186 192 114 80 250 698 165 567 95 7 262 352 6 18 423 49 487 749 118 556 114 97 298 439 54 542 984 223 237 562 221 582 60 288 563 669 325 537 336 126 406 513 305 511 522 311 606…
Output: 127532

Example 3:

Input: 661 2950 334 593 398 365 368 379 429 652 924 10 272 822 503 633 800 64 201 276 58 518 384 42 361 107 36 469 875 457 478 653 115 607 114 274 295 858 235 430 646 188 322 109 90 159 521 379 411 725 360 460 917 164 274 715 49 196 881 348 544 182 231 645 61 117 458 380 79 376 120 96 361 378 336 356 376 470 623 478 463 519 562 263 575 379 299 491 790 386 519 114 266 366 734 209 628 945 194 515 381 49 642 469 18 458 713 107 634 406 38 83 713 335 455 190 225 649 254 20 51 269 286 439 364 89 584 981 339 658 715 478 516 589 341 547 447 69 321 109 456 644 33 463 532 493 375 464 518 351 372 716 321 385 292 265 620 417 212 615 676 477 577 448 365 515 969 550 600 476 161 169 54 124 473 622 470 543 489 165 237 517 229 567 441 453 575 844 512 637 325 51 145 793 142 531 726 298 549 806 41 273 330 261 267 5…
Output: 85499

Constraints:

1 <= n <= 1142; 0 <= m <= 3426; 0 <= w <= 1000.

Loading...
Test Cases:No test cases
No test cases available.
Rohan's Cable Plan Ledger - MEDIUM Coding Problem | CodeTikki