CT44263

Hugo's Fastest Route Ledger

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

The measurer Hugo has been asked to publish the quarterly findings. On the desk lies a long table of bridges 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 <= 1437; 0 <= m <= 4311; 1 <= s,t,u,v <= n; 0 <= w <= 1000; distance fits 64-bit.

Example 1:

Input: 1427 3725 1 1427 119 661 169 253 1018 711 746 995 229 713 1267 440 1013 1333 688 363 828 727 1038 1385 975 91 307 455 232 903 799 216 1156 438 289 1082 222 380 973 878 80 455 33 351 942 386 757 1385 710 288 529 755 118 868 313 188 208 335 252 1036 106 35 538 849 10 135 126 49 1173 794 377 936 171 433 758 908 54 1246 978 558 746 965 295 1204 935 694 825 446 102 630 458 1128 1418 337 5 731 761 54 67 914 210 940 227 634 1145 621 4 1118 73 461 655 455 354 1399 854 403 560 37 270 793 4 546 708 16 40 1080 879 563 1324 173 17 1039 805 218 405 42 370 1265 987 8 727 400 96 966 37 166 948 986 292 1374 187 353 1364 950 183 1277 495 379 596 57 278 707 530 79 885 588 463 1147 97 74 1103 778 616 1165 913 393 1323 47 194 261 86 1132 1189 912 144 151 187 354 949 949 67 595 268 70 197 507 919 1021 658 333 …
Output: 1411

Example 2:

Input: 987 986 1 987 437 757 601 524 963 191 815 904 282 248 637 156 442 877 479 588 779 64 29 679 348 485 876 643 51 629 740 694 854 638 544 719 231 523 878 316 360 929 338 221 970 356 90 197 225 312 572 90 633 798 834 60 565 469 284 639 780 264 383 81 177 815 629 201 328 621 448 784 865 898 957 357 171 395 738 669 752 645 366 650 845 332 539 332 749 800 792 438 981 900 382 395 426 1 455 375 231 899 994 112 122 58 641 783 960 421 783 682 635 682 411 284 869 381 20 855 659 96 945 488 150 776 658 615 767 17 578 935 570 179 253 966 132 462 776 268 545 795 589 962 678 643 713 514 324 949 766 256 352 593 67 615 325 342 534 157 452 964 841 76 557 946 549 985 144 469 942 631 213 521 178 590 819 733 704 848 192 209 542 622 5 587 734 480 504 654 242 289 613 109 425 785 82 965 266 77 765 348 464 591 620 1…
Output: 6207

Example 3:

Input: 1415 1414 1 1415 163 1104 194 912 923 121 723 1185 292 334 453 920 290 1049 260 746 925 535 164 422 497 1040 1217 302 79 538 868 52 1388 323 505 1067 378 797 951 113 696 703 402 853 1096 766 1315 1344 651 255 946 208 787 1099 796 975 1044 60 913 1363 30 405 925 87 261 1301 235 144 971 214 1112 1213 554 829 1014 499 145 288 651 402 1296 755 543 1285 480 791 1054 291 62 1080 259 743 895 957 86 630 178 974 1408 250 644 971 351 17 647 589 312 853 947 796 1221 496 206 1244 451 1052 1296 17 1111 1259 6 510 762 528 681 1109 365 168 751 38 491 1405 380 866 1246 99 60 677 105 63 1213 255 1018 1338 862 681 1391 867 1277 1410 803 452 925 738 536 1314 278 151 783 254 42 641 122 138 164 290 799 995 354 820 1267 150 162 407 708 562 622 624 223 274 93 242 1133 726 321 1310 800 407 998 225 21 26 724 180 3…
Output: 2492

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Hugo's Fastest Route Ledger - MEDIUM Coding Problem | CodeTikki