CT48865

Kavya and the Ivory roads

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

The archivist Kavya has been asked to prepare the guildmaster's brief. On the desk lies a long table of roads 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 <= 1240; 0 <= m <= 3720; 1 <= s,t,u,v <= n; 0 <= w <= 1000; distance fits 64-bit.

Example 1:

Input: 1004 1003 1 1004 149 620 255 12 192 538 144 794 107 554 809 958 291 980 44 686 957 468 374 376 173 801 1004 204 137 181 498 253 365 596 288 886 323 74 103 331 34 44 51 27 540 761 471 527 342 962 997 656 563 902 659 285 632 359 464 732 363 186 428 131 37 952 808 452 912 880 354 882 932 690 801 15 407 811 199 157 943 31 468 857 849 491 602 594 756 884 580 117 376 725 294 603 653 433 486 802 6 769 921 386 501 236 313 933 455 483 857 551 75 899 729 551 910 834 89 318 923 925 983 796 652 965 863 721 760 473 182 754 975 133 728 265 275 515 497 31 170 99 467 582 734 202 260 541 79 523 529 176 727 174 484 694 299 279 468 838 519 918 292 115 141 100 450 555 101 351 718 597 193 965 447 253 545 826 297 802 566 131 368 426 23 27 548 345 830 480 472 639 396 334 559 76 164 668 882 756 926 126 349 540 91…
Output: 2853

Example 2:

Input: 450 2595 1 450 157 431 547 34 427 121 77 426 705 438 445 562 32 285 92 331 432 381 125 182 417 101 372 383 183 205 467 75 439 573 12 426 567 100 220 413 269 295 326 220 248 743 222 443 286 38 401 340 351 421 810 16 359 230 62 415 574 63 254 693 5 137 651 18 296 910 218 388 327 89 263 322 300 450 919 122 220 179 40 365 671 187 402 156 111 229 726 143 445 926 51 336 340 213 218 241 12 376 97 1 440 547 20 246 191 350 375 36 316 385 486 1 235 386 17 97 398 168 417 188 83 229 455 79 160 629 375 419 262 50 57 747 298 433 797 280 413 891 206 370 955 20 84 157 8 128 423 113 355 674 279 334 304 77 270 216 141 430 282 271 435 707 135 332 2 82 365 981 262 343 343 30 324 22 49 164 168 202 204 995 137 377 3 217 235 711 110 143 944 104 333 320 95 268 119 304 424 275 384 408 779 189 441 247 72 143 195 79…
Output: 877

Example 3:

Input: 382 494 1 382 51 363 87 256 281 644 302 359 870 219 270 866 150 269 576 35 328 556 79 300 662 196 204 348 214 253 52 204 368 361 282 363 728 277 358 683 151 163 687 61 222 520 48 154 894 155 182 380 144 183 240 72 241 74 65 210 577 288 341 46 11 346 290 223 302 262 119 359 226 14 126 544 265 377 988 13 14 707 119 121 615 158 235 835 50 178 425 19 296 151 29 226 993 114 284 36 10 112 132 163 306 995 155 349 200 244 290 243 220 328 621 119 287 88 22 380 179 242 245 548 26 142 140 186 325 14 204 361 458 184 230 243 110 332 382 159 209 211 207 213 333 15 280 685 165 220 399 296 308 691 108 283 803 320 336 810 40 79 340 265 341 743 215 246 981 36 184 576 21 298 877 59 149 582 192 297 676 249 260 836 185 195 1000 183 231 65 251 294 552 13 31 768 351 352 742 35 177 191 17 108 230 122 130 855 84 3…
Output: 2287

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Kavya and the Ivory roads - MEDIUM Coding Problem | CodeTikki