CT34456

The Fewest Hops of Stormrest

MediumL4 · Loop LordAcceptance: 0.0%XP: 35

Caravans arrive at the cliffside roost of Stormrest with crates of routes, and Orin the surveyor must account for every last one. Task: Print the minimum number of edges on a path from s to t, or -1. Input format: First line: n m s t. Next m lines: u v. Output format: Print the BFS distance or -1. Constraints: 1 <= n <= 1948; 0 <= m <= 3896.

Example 1:

Input: 837 836 1 837 356 749 14 641 5 590 238 440 71 392 302 824 474 515 121 205 98 160 160 273 145 490 198 239 303 751 304 307 75 622 229 458 190 766 723 767 226 308 62 493 765 809 6 213 378 491 329 600 334 826 59 821 88 546 185 375 150 535 63 346 255 446 38 241 350 438 211 469 558 614 476 803 337 755 32 34 684 727 28 549 135 311 237 241 331 822 456 762 347 350 372 634 256 797 17 548 271 515 175 466 128 183 486 773 667 758 714 809 605 832 252 284 107 335 145 776 133 285 592 759 445 803 76 219 462 724 740 759 88 676 497 498 170 798 214 365 368 567 141 238 465 708 23 743 255 387 464 603 487 721 69 178 417 543 53 543 338 377 327 711 485 665 407 565 90 511 518 747 124 458 41 521 439 828 315 689 216 660 141 255 325 422 21 276 91 345 232 728 305 459 398 798 523 724 403 803 72 75 310 535 198 545 126 19…
Output: 11

Example 2:

Input: 1039 3427 1 1039 674 1012 631 669 610 745 46 742 379 821 374 532 505 912 202 842 740 881 408 904 536 551 536 581 903 1030 179 306 636 726 450 838 137 828 191 593 509 696 448 571 626 983 500 1026 533 908 411 678 727 1012 723 862 55 595 420 973 601 779 238 717 215 1028 856 890 581 611 863 934 707 951 291 728 91 238 5 406 80 619 56 184 729 952 255 449 419 957 78 375 192 968 183 316 270 721 953 983 242 626 705 868 633 769 207 937 550 1033 131 867 482 903 473 691 264 373 672 896 111 870 161 400 234 366 427 450 421 849 148 424 66 916 378 383 205 580 509 819 338 498 247 813 585 738 84 713 242 822 163 890 115 560 357 786 639 774 367 478 73 846 286 533 4 573 91 908 312 439 324 438 574 695 212 406 140 667 366 840 530 763 321 328 170 212 225 597 518 937 683 758 242 646 489 903 651 1007 508 724 468 84…
Output: 5

Example 3:

Input: 1377 1376 1 1377 628 942 610 1273 797 1234 121 358 819 1262 506 1122 11 954 75 363 996 1128 789 859 828 1283 569 1295 366 962 1131 1250 167 758 237 1132 246 451 33 1089 425 1104 691 813 691 1116 150 1241 773 1083 289 427 551 635 56 473 538 611 1006 1026 194 437 33 788 289 1107 2 531 71 611 781 1104 210 570 16 70 269 457 81 978 526 884 117 240 751 1240 12 1301 462 603 640 1275 286 1121 897 1256 194 619 680 704 8 579 946 1256 198 745 166 1244 410 965 894 1294 795 1347 863 1118 708 1369 967 1365 337 939 25 1291 91 1040 1228 1352 141 1166 1202 1223 303 1154 1103 1115 775 794 157 496 401 1213 281 500 182 208 600 1075 418 921 546 1169 1287 1338 311 518 140 1137 1108 1303 386 1097 901 1149 313 488 450 640 264 1026 2 850 106 287 524 1238 599 1198 113 1203 413 1357 934 1150 70 842 1256 1363 1195 13…
Output: 20

Constraints:

1 <= n <= 1948; 0 <= m <= 3896.

Loading...
Test Cases:No test cases
No test cases available.
The Fewest Hops of Stormrest - MEDIUM Coding Problem | CodeTikki