CT60803

Tanya and the Cable Plan

MediumL6 · Pointer PhantomAcceptance: 0.0%XP: 100

The inventory keeper Tanya has been asked to tally the donation drive. On the desk lies a long table of routes readings. 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 <= 898; 0 <= m <= 2694; 0 <= w <= 1000000.

Example 1:

Input: 456 977 122 329 465463 114 422 825271 64 448 448380 257 289 41989 22 171 134487 143 200 730243 407 443 386627 225 403 1633 113 211 584785 423 425 912184 201 412 808416 211 284 18653 94 386 313476 191 406 508206 198 411 396920 58 303 251364 16 101 285359 288 334 28157 409 439 290970 126 399 971580 121 283 350026 132 307 469103 25 117 342575 136 354 754969 222 295 364194 67 191 419748 40 50 273726 80 301 972614 42 70 549792 345 372 579541 166 194 325394 101 134 168750 203 338 637512 54 115 57558 76 217 61670 119 245 981276 318 325 782204 98 228 378538 53 148 135464 192 277 284058 139 323 349091 334 387 567418 325 410 972881 369 412 488118 31 251 771287 219 363 823294 254 425 188532 264 279 829267 163 249 691324 100 189 219182 236 375 614718 129 450 388492 109 217 303976 171 417 396667 156 25…
Output: 125009051

Example 2:

Input: 344 1251 328 333 835677 140 242 919651 186 336 593668 24 240 191588 13 290 573049 28 29 191872 38 331 171237 91 286 765602 33 252 17361 81 190 834996 112 307 308569 13 217 233377 133 276 133828 62 110 209177 218 219 26067 266 296 369861 98 319 169747 24 73 924332 65 171 866205 165 300 137574 108 260 654280 119 316 263502 84 206 125782 96 142 31132 33 253 449905 140 249 925513 152 323 323150 255 318 580250 168 219 165199 149 193 137333 79 90 332547 59 322 297781 228 294 619318 14 71 574164 141 286 689692 26 312 230012 17 174 932857 43 95 667042 257 292 667765 241 304 979717 175 260 949293 158 209 841503 95 343 605550 32 225 370791 51 285 104564 47 335 118038 112 255 947059 80 338 787067 81 212 972275 41 195 662387 63 192 369294 53 178 612165 46 150 4384 151 279 207277 110 149 351443 143 301…
Output: 54026197

Example 3:

Input: 401 1636 177 251 83186 179 378 822607 64 229 940614 224 374 881661 69 136 556230 210 243 607038 296 307 814835 249 365 352180 7 47 805698 277 382 777282 122 355 927215 138 370 38418 34 324 573117 163 396 474784 190 208 731785 256 350 233150 37 330 777882 269 311 148806 7 309 74560 181 386 352499 101 304 727075 5 349 742220 290 308 896754 228 371 706509 136 255 42968 270 369 690144 161 170 109688 223 296 366304 55 59 574281 50 236 969957 314 354 266667 80 274 763056 41 236 385240 95 184 626490 230 304 142015 81 288 337076 138 289 708722 136 145 839217 21 216 109729 112 195 322955 206 226 357783 278 293 201042 113 269 948308 75 205 994521 4 70 48325 192 280 566474 28 341 307419 112 233 115512 34 369 395545 127 180 636057 5 147 829112 174 284 401204 158 246 189314 171 205 532727 21 131 5448 1…
Output: 57600522

Constraints:

1 <= n <= 898; 0 <= m <= 2694; 0 <= w <= 1000000.

Loading...
Test Cases:No test cases
No test cases available.
Tanya and the Cable Plan - MEDIUM Coding Problem | CodeTikki