CT62751

Devi's bridges Cable Plan

MediumL6 · Pointer PhantomAcceptance: 0.0%XP: 100

Every season at the mountain city of Highreach, someone must prove the quality of the harvest. This year the task falls to Devi, armed only with the bridges register. 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 <= 1080; 0 <= m <= 3240; 0 <= w <= 1000.

Example 1:

Input: 676 1355 507 535 980 183 464 522 365 376 851 268 623 349 392 511 595 487 635 194 108 298 903 74 568 428 256 434 555 145 332 715 63 511 632 165 659 739 66 85 13 15 116 230 238 344 731 114 270 617 189 483 991 104 130 379 316 398 777 93 444 895 115 244 56 167 191 32 187 304 957 648 657 538 83 587 634 38 350 7 346 361 240 91 139 418 541 612 671 186 417 926 77 339 563 138 387 880 482 642 525 183 520 712 266 491 744 17 125 504 256 297 497 175 421 544 18 382 801 486 570 428 249 651 703 418 590 33 357 450 344 363 628 356 163 452 106 184 620 996 77 476 424 366 566 817 31 265 266 186 208 337 596 606 81 105 257 306 566 650 198 22 566 646 293 642 133 345 421 15 167 655 901 553 616 521 29 44 566 247 428 992 109 656 17 384 587 140 243 393 811 458 590 783 56 628 690 97 527 115 172 177 769 318 331 93 350 …
Output: 202157

Example 2:

Input: 19 171 3 16 903 11 14 333 15 19 449 15 18 355 1 9 127 2 3 359 9 16 721 1 3 645 5 17 946 9 15 210 8 19 74 8 15 536 10 17 180 14 18 425 10 11 524 3 15 970 1 13 704 13 15 143 3 4 251 3 11 544 7 12 9 2 4 352 13 19 363 1 14 232 7 8 365 7 11 853 5 11 236 6 18 790 13 17 392 5 16 685 2 8 951 7 9 932 6 11 192 10 16 23 2 5 840 6 16 150 4 15 492 12 13 422 4 6 498 8 14 689 12 16 479 14 17 737 4 13 14 6 10 597 8 10 246 12 15 337 1 18 85 5 14 84 1 12 147 4 14 98 2 6 411 1 2 118 4 16 363 5 13 152 9 12 812 13 14 248 1 16 132 15 17 551 2 7 833 10 15 457 2 19 78 1 5 621 5 9 249 4 7 931 9 10 444 7 15 843 16 17 49 11 13 186 1 6 258 9 19 443 10 13 126 9 18 99 14 16 192 2 15 476 6 13 567 9 11 747 1 7 893 3 12 168 6 19 690 8 17 993 5 10 601 8 16 860 11 17 109 3 5 587 6 7 894 6 12 491 5 7 326 8 9 409 8 13 223 10 …
Output: 1164

Example 3:

Input: 485 2935 115 310 998 302 423 695 28 472 390 303 447 81 202 255 8 76 112 203 204 217 356 243 459 890 12 29 358 258 283 683 129 439 268 295 314 746 379 414 985 116 318 218 135 425 996 96 365 298 311 416 736 108 419 389 132 415 8 389 418 527 120 173 118 300 372 491 169 331 494 29 448 588 194 356 658 395 459 948 252 421 907 291 317 770 183 235 668 327 427 561 178 181 335 180 268 279 219 429 274 107 247 407 12 427 318 60 397 647 33 466 684 6 28 987 321 385 984 114 214 751 46 377 516 96 334 886 130 340 734 61 174 372 144 191 758 348 435 202 401 418 607 85 362 563 10 477 319 176 242 645 4 474 492 213 354 377 36 431 191 199 329 417 381 466 599 296 376 836 118 484 349 69 480 341 249 296 609 193 322 53 78 292 991 351 462 254 48 455 386 97 482 668 164 436 25 117 223 459 301 474 695 64 112 579 194 359…
Output: 49326

Constraints:

1 <= n <= 1080; 0 <= m <= 3240; 0 <= w <= 1000.

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