CT45581

The Silkmead Fastest Route

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

The bookkeeper Lara has been asked to map a faster supply route. On the desk lies a long table of routes readings. Task: An undirected weighted graph is given. Print the shortest-path cost from s to t, or -1 if unreachable. Input format: First line: n m s t. Next m lines: u v w. Output format: Print the shortest distance or -1. Constraints: 1 <= n <= 1671; 0 <= m <= 5013; 1 <= s,t,u,v <= n; 0 <= w <= 1000; distance fits 64-bit.

Example 1:

Input: 1394 4247 1 1394 934 1053 252 349 904 840 508 1343 298 583 1119 502 68 356 2 137 628 118 212 1019 465 301 678 389 63 471 97 1001 1222 779 79 1147 683 752 941 307 300 444 163 424 707 610 1030 1276 627 150 1215 515 372 518 853 90 1372 18 354 1144 189 913 1180 642 512 734 878 965 1265 617 436 903 882 225 398 371 842 1002 876 47 921 871 69 626 432 332 491 299 183 940 709 830 832 56 62 455 814 263 966 741 863 1373 53 436 1274 785 18 779 799 390 1196 47 114 137 669 1032 1145 517 788 1038 643 1087 1304 944 190 987 519 709 1274 994 159 1156 405 210 1289 568 860 978 273 132 759 280 595 1073 8 223 968 470 592 594 705 400 912 719 742 1010 360 349 1013 740 798 1153 482 497 1173 136 842 962 279 1049 1318 563 940 1128 390 284 764 66 407 1159 865 201 1221 329 110 1193 839 138 483 727 823 1359 533 104 100…
Output: 2263

Example 2:

Input: 370 2150 1 370 318 355 821 12 230 505 79 166 919 278 362 558 162 168 545 157 353 987 162 337 373 12 67 654 9 331 527 152 231 121 197 226 82 35 134 425 34 239 677 311 358 854 120 302 571 65 301 332 47 73 251 9 181 452 326 357 464 115 176 499 18 48 159 184 234 937 78 188 690 3 199 644 279 353 735 76 138 396 70 87 534 63 123 543 199 334 508 288 353 493 162 363 393 112 355 929 208 356 589 277 323 40 90 294 724 97 219 132 231 337 85 5 98 112 169 243 449 126 198 38 93 219 153 90 192 435 14 33 463 105 244 229 44 340 636 148 284 492 186 196 386 77 336 919 194 367 728 84 124 182 319 330 945 85 304 659 187 288 731 273 277 188 267 363 354 175 231 681 157 351 473 48 353 32 22 261 270 54 180 433 175 294 533 225 341 73 247 338 945 146 171 179 61 159 113 280 335 131 3 358 247 240 301 477 194 306 900 113 …
Output: 446

Example 3:

Input: 2 1 1 2 1 2 580
Output: 580

Constraints:

1 <= n <= 1671; 0 <= m <= 5013; 1 <= s,t,u,v <= n; 0 <= w <= 1000; distance fits 64-bit.

Loading...
Test Cases:No test cases
No test cases available.
The Silkmead Fastest Route - MEDIUM Coding Problem | CodeTikki