CT49924

Quartermaster's Moonlit Ledger

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Caravans arrive at the monsoon port of Rainhaven with crates of corridors, and Quartermaster the ledger master 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 <= 3935; 0 <= m <= 7870.

Example 1:

Input: 1287 1286 1 1287 637 1012 276 744 434 594 27 163 106 162 9 543 31 457 209 695 829 1023 189 547 35 1002 326 356 136 774 636 741 608 970 683 840 657 664 804 1121 536 1174 1067 1238 138 1074 604 623 1137 1264 194 249 140 737 571 1182 61 1282 627 972 126 924 109 959 610 1187 131 512 40 620 617 1215 298 554 131 763 283 1010 442 1184 24 1267 525 1065 963 972 447 547 406 1015 282 607 267 858 35 111 408 1278 282 495 135 883 392 826 361 715 179 199 290 1052 344 933 166 584 909 1015 937 1019 302 1167 645 1049 617 1027 202 802 304 646 17 1152 36 417 439 546 675 1125 309 531 677 1105 434 909 609 1247 60 787 57 718 459 1281 1114 1272 916 1258 319 682 738 1167 911 1123 493 638 496 504 510 1178 560 618 591 750 614 972 1187 1192 524 1089 511 1087 753 983 97 1243 757 1199 419 529 23 1277 27 1024 36 1153 81…
Output: 10

Example 2:

Input: 2291 2677 1 2291 462 2029 171 1275 1779 2282 108 1337 246 880 1011 1408 104 1775 2148 2220 976 2120 425 1263 818 1902 1322 1346 662 2133 1631 1724 83 1154 190 417 963 1849 423 1693 1418 2124 388 1820 742 1568 365 1786 1502 1832 927 1907 266 1012 806 1194 850 1794 898 1569 430 1425 212 2244 239 1258 1218 2248 487 1767 966 2163 78 1820 419 820 690 2288 28 1026 1427 2064 1474 1881 983 1111 1460 1785 318 526 903 2244 760 1149 176 1541 2024 2258 1987 2165 549 1278 1160 1441 817 1197 373 704 122 1032 1863 2154 114 1285 1319 2273 729 1228 938 1438 22 581 825 2105 305 1907 1206 1626 607 1436 1309 1645 143 1824 310 1762 958 1030 93 2011 2076 2093 892 1646 390 843 654 1219 218 2117 515 1604 176 848 151 1086 1524 1574 415 1732 137 701 1286 2056 418 1220 1444 2261 302 1048 1816 2042 409 1564 442 1013 …
Output: 11

Example 3:

Input: 3811 3810 1 3811 2671 2714 975 3047 3330 3341 426 2223 270 1770 1396 3203 1161 2338 1177 2023 123 1521 2253 3462 390 2894 2496 2843 1741 2578 1921 3496 1532 3430 255 2076 2110 3383 77 984 81 1708 1803 2420 318 3694 2722 3628 2820 3084 2297 2322 1958 2876 2019 3412 539 1371 608 3431 1898 3093 1726 3810 1407 3082 208 899 1056 2944 198 1124 203 708 2419 2777 901 1376 1153 3208 1055 1288 1767 2939 1444 2613 1515 3306 1621 3293 2265 3699 1032 3203 96 3201 1649 2759 1779 2749 686 2825 2168 3531 2172 3246 124 1337 742 1710 795 3024 281 3624 466 2263 1731 2373 2219 2392 3589 3598 1901 2616 233 3076 683 2589 3091 3784 1076 3429 919 2904 1190 2509 2830 3611 1430 2020 1989 3565 1652 1834 2085 2846 346 1770 1309 2486 1837 2752 2235 2885 575 3772 1615 2323 389 1191 1481 3420 2327 2746 2281 2646 1151 20…
Output: 10

Constraints:

1 <= n <= 3935; 0 <= m <= 7870.

Loading...
Test Cases:No test cases
No test cases available.
Quartermaster's Moonlit Ledger - MEDIUM Coding Problem | CodeTikki