CT60974

Last roads of Bhanu

MediumL6 · Pointer PhantomAcceptance: 0.0%XP: 100

Legend says the vault under the mulberry rows of Silkmead opens only for a perfect tally of roads. Bhanu 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 <= 1078; 0 <= m <= 3234; 0 <= w <= 1000.

Example 1:

Input: 109 3024 11 27 658 23 66 224 37 89 564 59 102 735 60 108 294 55 99 939 27 89 549 15 101 935 69 97 507 36 65 591 102 109 641 64 92 473 93 97 463 39 45 751 91 95 120 10 49 896 48 93 687 50 81 461 38 107 783 44 75 308 52 88 704 50 89 114 18 80 817 26 56 227 9 21 157 86 96 51 20 30 715 24 79 657 87 94 35 28 109 562 31 47 426 69 85 799 25 83 213 8 27 960 6 26 96 65 103 626 45 86 12 15 33 947 51 56 403 19 87 633 60 74 643 28 63 368 28 51 89 19 74 209 76 95 179 30 61 950 20 39 56 20 33 438 2 77 132 35 71 392 68 96 547 63 78 230 4 56 511 35 50 786 99 101 38 5 29 794 92 100 635 25 103 245 13 80 94 40 47 877 19 60 319 45 53 610 49 54 418 42 108 863 35 69 258 17 42 673 51 86 266 57 105 921 56 66 410 64 80 344 5 57 515 20 23 850 19 25 915 25 67 698 12 88 441 89 94 347 106 109 613 56 92 98 8 72 372 73 …
Output: 2258

Example 2:

Input: 502 1548 271 358 873 73 489 651 40 443 325 82 320 732 146 219 759 84 164 562 240 396 641 85 120 491 225 346 95 224 228 490 212 295 375 95 138 203 120 360 228 82 299 306 245 268 730 157 351 735 373 471 324 177 448 254 70 338 166 279 411 820 56 270 279 60 465 697 137 262 56 251 431 397 399 443 805 372 432 788 2 360 689 39 326 582 30 45 215 380 389 175 142 259 889 318 399 200 346 407 336 175 445 936 125 367 407 96 199 187 372 387 673 323 409 750 36 114 25 121 173 791 58 341 934 70 370 210 49 502 848 131 234 298 249 336 200 196 201 605 30 228 583 83 159 47 102 363 267 29 318 984 168 204 447 207 498 58 347 458 914 80 488 310 342 354 351 392 495 157 332 448 437 188 369 449 1 367 228 218 464 375 75 329 202 105 327 878 286 335 642 284 420 568 314 378 583 45 416 31 64 479 181 110 492 48 224 391 977…
Output: -1

Example 3:

Input: 6 15 1 5 41 4 6 559 2 5 711 3 6 747 1 2 859 5 6 431 1 6 425 1 4 454 4 5 889 1 3 865 2 3 277 3 4 603 2 4 107 3 5 250 2 6 25
Output: 700

Constraints:

1 <= n <= 1078; 0 <= m <= 3234; 0 <= w <= 1000.

Loading...
Test Cases:No test cases
No test cases available.
Last roads of Bhanu - MEDIUM Coding Problem | CodeTikki