CT53565

Yami's Fewest Hops Ledger

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Legend says the vault under the fox den of Rustwood opens only for a perfect tally of routes. Yami means to find out. 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 <= 1835; 0 <= m <= 3670.

Example 1:

Input: 260 1086 1 260 58 197 81 129 18 26 56 137 48 100 124 165 21 102 94 213 21 53 62 86 156 204 130 187 86 233 24 247 66 174 2 125 85 137 17 90 101 183 135 151 81 101 23 152 2 120 44 173 252 260 10 150 79 145 182 220 63 75 29 103 31 125 13 95 24 194 65 107 155 194 34 161 29 104 84 163 6 144 215 246 20 44 1 42 36 230 81 233 12 161 213 221 44 120 120 153 56 120 27 253 29 195 62 148 84 110 185 200 1 244 181 217 90 134 184 231 185 208 96 174 112 215 108 213 104 222 17 62 129 215 241 251 179 212 53 177 79 116 132 210 29 222 112 213 92 245 28 39 73 168 101 254 149 238 171 181 69 212 82 145 224 244 46 47 8 190 102 129 218 244 31 183 206 254 109 174 238 259 26 56 103 215 29 204 2 237 157 235 7 120 112 115 166 259 160 250 105 123 160 169 68 126 245 248 23 212 131 217 13 111 76 81 111 257 41 243 189 255 …
Output: 2

Example 2:

Input: 1018 1931 1 1018 57 470 313 958 745 770 253 317 191 617 733 751 60 743 334 615 774 920 769 812 279 944 795 951 51 780 179 871 39 340 34 855 862 945 155 331 460 623 451 920 457 974 477 689 241 306 567 686 470 974 350 926 39 421 735 754 80 92 110 128 54 403 640 679 51 98 61 470 36 938 107 772 396 809 219 934 516 517 184 303 119 515 394 1010 700 793 578 702 387 858 109 987 392 468 501 819 675 741 413 870 274 822 452 671 366 493 266 286 128 436 19 584 205 561 194 947 624 795 132 412 85 867 268 455 614 644 544 645 36 816 182 270 346 569 277 653 221 225 10 133 142 321 240 284 198 406 437 562 122 150 10 42 219 323 703 938 401 874 186 988 211 456 187 604 129 499 224 1008 399 445 354 434 171 1007 615 748 171 557 462 488 17 54 390 887 127 715 64 900 55 214 101 474 920 933 382 689 317 329 496 727 764…
Output: 4

Example 3:

Input: 1400 1433 1 1400 976 1317 558 816 929 1069 617 954 388 1128 502 1029 843 1146 202 601 662 1040 803 885 412 901 200 1272 2 257 208 1231 618 1056 361 379 290 1222 920 991 1234 1360 93 611 22 51 296 1160 351 1159 409 481 26 402 215 1316 349 1359 233 1361 87 427 315 989 1222 1283 617 921 180 244 1232 1267 324 1382 183 454 858 1279 378 1052 73 1301 134 818 222 834 286 656 195 603 453 729 19 167 146 329 741 1241 1344 1359 686 729 67 558 592 949 459 1308 41 148 788 881 336 1342 390 886 492 726 14 431 705 1245 284 691 899 1139 222 827 272 937 1116 1185 222 600 36 130 11 524 75 1329 820 1167 197 198 399 644 79 422 167 773 736 925 529 1167 495 1219 826 1210 64 275 617 781 773 1176 538 1066 240 673 150 1200 334 1051 667 1158 19 599 151 632 431 1396 140 783 326 1183 346 522 251 938 431 969 320 1311 91…
Output: 12

Constraints:

1 <= n <= 1835; 0 <= m <= 3670.

Loading...
Test Cases:No test cases
No test cases available.
Yami's Fewest Hops Ledger - MEDIUM Coding Problem | CodeTikki