CT53282

Secret canals Fewest Hops

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Deep in the archive halls of Scrollkeep, Theo studies rows of canals entries. One clean number will settle the guild's oldest argument. 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 <= 1530; 0 <= m <= 3060.

Example 1:

Input: 791 790 1 791 669 709 114 653 253 432 159 776 288 676 194 393 64 153 16 378 140 283 459 586 191 333 415 554 521 719 137 435 254 654 434 681 199 747 71 100 384 655 227 741 615 676 176 344 129 271 20 504 285 495 99 650 323 423 134 706 174 309 191 488 131 429 430 555 363 767 399 778 81 85 554 611 157 351 64 127 62 631 603 604 167 666 392 421 115 284 78 716 600 632 12 30 655 687 171 768 710 739 332 559 33 339 62 447 99 731 199 347 33 233 232 265 36 494 299 308 149 790 422 767 118 352 538 541 348 645 288 568 689 780 92 377 29 519 217 277 53 401 39 548 71 499 40 747 134 485 224 491 367 752 9 711 290 414 232 665 544 622 215 256 191 261 39 82 97 282 60 311 92 456 406 527 102 600 42 254 139 776 362 496 22 425 84 160 394 468 187 295 234 550 378 612 402 688 216 313 178 637 147 790 477 620 200 752 88 …
Output: 9

Example 2:

Input: 259 1980 1 259 97 104 49 52 128 147 97 129 129 131 50 230 10 128 29 198 7 44 6 135 128 175 20 61 61 147 77 181 100 158 157 200 50 161 102 184 13 209 202 241 3 146 14 54 161 171 38 81 67 89 6 239 52 221 109 206 73 214 147 247 55 154 23 229 111 157 25 89 111 189 71 208 68 250 117 209 28 81 38 129 24 196 54 81 23 31 67 238 53 188 113 135 84 144 24 34 4 23 29 191 57 233 82 113 70 195 25 139 43 247 193 212 21 248 111 195 118 193 102 236 184 225 27 256 30 221 69 169 221 229 41 212 42 141 183 189 83 255 33 79 13 42 3 162 46 231 43 122 108 130 104 194 3 50 53 222 27 225 30 144 56 206 84 159 58 174 92 171 32 142 18 195 36 148 44 74 218 237 137 204 42 157 124 188 40 112 183 209 124 171 188 240 144 162 223 234 44 75 21 187 2 155 197 257 94 219 9 223 40 69 137 250 68 119 99 237 107 142 134 228 142 213…
Output: 2

Example 3:

Input: 1125 1124 1 1125 145 851 750 861 530 537 62 314 721 1005 133 950 527 661 138 830 321 889 382 446 388 692 814 969 342 824 58 367 323 907 284 412 30 975 21 961 357 885 533 645 221 799 213 778 91 666 642 741 612 616 164 389 22 580 216 988 70 84 72 761 146 443 121 686 313 691 424 922 432 847 245 648 74 330 659 1020 57 574 467 508 436 822 536 608 161 578 237 472 240 1028 305 637 61 278 261 565 226 1019 4 716 15 179 189 425 75 171 880 923 779 837 578 1114 110 642 342 956 221 1050 230 925 11 714 864 1078 711 1062 212 991 408 1121 879 1104 287 817 394 928 675 1019 183 402 253 374 21 758 282 650 14 409 73 434 250 536 338 676 215 624 23 433 826 1022 424 1096 4 327 205 904 86 855 355 402 411 1067 241 502 367 992 124 166 444 903 95 194 279 1040 557 855 988 1013 55 309 356 385 851 881 876 905 260 456 4…
Output: 15

Constraints:

1 <= n <= 1530; 0 <= m <= 3060.

Loading...
Test Cases:No test cases
No test cases available.
Secret canals Fewest Hops - MEDIUM Coding Problem | CodeTikki