CT58585

The routes Cable Plan Puzzle

MediumL6 · Pointer PhantomAcceptance: 0.0%XP: 100

At the glass towers of Prismhaven, Tara records each routes in a worn leather ledger. The guild wants answers, not guesses. 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 <= 1087; 0 <= m <= 3261; 0 <= w <= 1000.

Example 1:

Input: 364 2561 46 101 844 80 97 252 19 80 159 318 354 422 212 273 670 18 334 361 180 330 166 58 83 623 144 319 727 149 208 787 327 329 789 204 341 758 41 314 480 22 285 434 23 279 41 223 353 195 43 225 774 205 357 151 110 267 856 159 220 152 162 267 541 24 141 234 5 67 172 10 177 346 131 267 762 58 313 584 7 206 559 78 214 16 244 251 840 218 300 92 81 357 416 24 191 827 28 165 22 96 169 413 118 340 919 277 336 173 75 132 334 59 95 611 125 232 757 217 354 231 209 307 367 52 248 468 165 211 958 128 257 287 108 282 173 210 220 706 5 45 906 182 341 690 249 313 390 56 327 945 79 114 854 8 41 241 98 187 295 271 272 588 287 337 428 180 296 482 32 53 868 232 306 982 171 319 780 7 33 357 148 173 470 21 182 302 89 281 681 1 285 897 218 253 240 187 357 219 245 323 655 105 185 37 35 323 951 86 348 458 28 28…
Output: 31090

Example 2:

Input: 340 3006 107 121 185 192 264 42 208 237 478 31 103 108 294 299 401 187 196 872 259 298 610 102 148 829 192 269 365 226 302 542 90 325 287 56 306 920 170 186 693 259 296 364 66 78 691 93 104 12 104 246 619 130 278 123 17 168 842 19 35 385 141 286 859 231 233 977 114 204 193 197 283 339 50 55 136 76 110 677 276 294 368 33 184 685 89 305 460 74 96 724 44 297 160 53 312 677 119 302 116 214 315 666 67 117 249 109 312 444 150 295 122 19 333 252 121 224 819 46 264 797 202 298 594 112 213 396 89 213 951 295 336 699 189 205 100 76 313 445 258 286 418 93 338 429 17 285 611 41 170 778 32 56 845 111 214 520 96 154 584 125 135 32 28 287 613 106 192 182 236 262 753 122 243 257 309 337 682 81 125 54 270 299 279 11 59 264 113 190 264 123 260 35 133 141 165 209 274 153 61 171 638 154 269 724 2 218 693 3 27…
Output: 23620

Example 3:

Input: 495 1170 350 365 691 445 470 431 339 350 629 306 476 238 45 247 407 157 290 241 104 440 645 50 71 202 178 412 253 100 144 331 264 395 457 131 260 818 52 210 695 274 402 256 172 439 149 269 463 56 17 22 283 314 350 3 206 361 521 216 427 675 194 347 947 274 459 304 194 325 400 30 262 959 189 218 236 88 291 64 259 281 199 228 325 652 3 172 17 150 212 413 111 355 763 97 393 15 5 254 432 154 262 35 411 466 157 233 458 505 161 316 132 26 442 265 273 340 625 329 368 529 25 109 945 60 225 133 263 472 341 4 398 937 10 138 560 43 386 47 84 135 139 223 361 357 317 436 765 127 212 125 98 439 978 36 475 417 1 148 887 239 285 901 237 375 239 252 355 935 150 494 686 313 460 851 163 331 42 285 331 866 216 340 398 113 394 353 89 202 768 154 209 385 281 426 278 229 400 345 62 249 953 47 142 636 226 243 533 …
Output: 111294

Constraints:

1 <= n <= 1087; 0 <= m <= 3261; 0 <= w <= 1000.

Loading...
Test Cases:No test cases
No test cases available.
The routes Cable Plan Puzzle - MEDIUM Coding Problem | CodeTikki