CT63104

Zoravar and the Pale bridges

MediumL6 · Pointer PhantomAcceptance: 0.0%XP: 100

The harbor bell rings at the windmill fields of Gusthaven; Zoravar weighs the day's bridges manifests and starts the calculations. 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 <= 1547; 0 <= m <= 4641; 0 <= w <= 1000.

Example 1:

Input: 1378 3754 79 1217 720 694 1184 449 301 630 793 509 622 676 686 1093 705 1236 1363 867 354 620 612 272 1256 882 184 1328 576 32 1366 51 808 1224 216 375 1129 270 111 1085 203 237 760 686 75 1322 329 215 1080 381 521 1080 605 849 905 167 2 1148 900 1247 1325 698 496 697 421 370 1234 54 151 675 551 24 1017 513 777 1355 185 513 972 815 313 1279 230 201 693 683 458 978 580 220 226 854 177 284 666 945 1218 906 41 160 542 136 994 876 689 957 293 412 593 38 428 873 198 116 202 84 88 189 422 705 845 947 818 1019 885 245 1233 783 48 953 834 204 514 301 962 1335 859 53 1333 633 126 904 35 78 1132 789 137 599 628 780 933 770 490 761 906 356 1143 263 498 1191 39 441 656 430 576 1026 745 126 749 924 7 1370 600 1019 1057 519 370 609 944 35 954 317 360 1349 477 1149 1320 644 648 795 278 170 625 344 152 10…
Output: -1

Example 2:

Input: 480 3536 216 285 673 67 476 130 207 243 689 340 387 317 173 442 882 185 457 773 11 269 553 33 135 903 175 462 181 64 242 447 227 435 706 465 471 345 76 359 219 37 309 152 150 451 400 232 291 194 71 289 78 358 399 8 299 460 571 157 278 196 26 123 952 4 109 656 355 441 78 137 338 564 216 329 955 258 270 655 338 379 661 356 476 317 178 192 655 220 398 279 64 246 667 224 412 349 74 279 242 140 355 144 85 200 631 12 115 395 36 186 695 439 441 158 80 295 381 344 458 769 234 379 896 79 247 950 223 249 147 466 469 879 15 330 947 2 335 356 215 345 558 108 116 610 22 304 121 124 284 370 169 338 927 245 276 535 245 470 299 173 323 294 42 98 637 8 252 49 130 190 578 203 447 73 226 253 34 72 300 820 128 178 943 121 165 298 405 455 275 285 396 361 348 457 330 4 274 973 14 346 707 195 262 415 34 365 802 …
Output: 43418

Example 3:

Input: 549 3490 170 420 241 246 546 868 295 396 772 426 467 447 313 350 682 103 367 982 5 46 691 318 473 938 92 261 549 124 192 970 179 320 323 105 203 256 129 330 152 160 447 108 140 448 737 124 477 79 76 133 66 19 402 890 62 421 390 249 531 220 463 492 219 351 461 666 214 409 102 149 329 572 361 449 486 346 527 139 373 488 828 40 418 820 39 331 662 304 434 737 191 214 907 160 243 335 88 115 158 66 441 630 220 492 479 237 414 47 380 421 572 179 474 48 103 216 57 49 538 366 234 249 118 80 492 804 209 355 762 266 280 930 135 201 134 69 327 51 240 390 856 259 399 296 388 503 366 6 191 617 202 497 806 172 377 925 34 509 746 104 216 74 193 206 192 16 467 36 249 360 454 446 510 266 345 420 553 197 454 514 191 269 688 41 393 621 57 140 918 217 257 56 43 284 676 288 314 249 103 287 37 5 153 252 245 356 …
Output: 50187

Constraints:

1 <= n <= 1547; 0 <= m <= 4641; 0 <= w <= 1000.

Loading...
Test Cases:No test cases
No test cases available.
Zoravar and the Pale bridges - MEDIUM Coding Problem | CodeTikki