CT34168

Lysander and the Fewest Hops

MediumL4 · Loop LordAcceptance: 0.0%XP: 35

The council of the cinnabar mines of Vermilion pays by the answer, and Lysander intends to earn it. First: the full register of corridors. 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 <= 1863; 0 <= m <= 3726.

Example 1:

Input: 934 2132 1 934 409 675 273 713 57 64 281 282 800 874 192 784 5 138 42 864 147 546 392 574 9 869 421 486 704 863 71 879 548 611 264 769 401 861 417 731 185 506 34 480 150 917 52 447 327 542 344 502 45 243 151 599 433 615 714 810 85 427 252 258 372 700 323 888 278 659 480 795 244 378 150 167 406 800 384 407 245 321 880 918 115 557 176 716 230 307 123 599 122 485 247 320 58 488 680 805 468 737 587 802 34 298 59 340 19 636 685 892 695 747 45 208 57 179 182 674 245 756 102 843 5 887 8 625 103 560 364 595 150 776 279 773 715 861 126 131 636 896 131 802 618 741 30 603 62 112 620 755 283 724 177 344 467 599 109 390 682 901 374 416 27 223 75 111 2 545 199 382 388 470 4 874 35 920 356 882 361 502 611 823 202 218 216 234 39 387 53 667 363 792 155 719 203 918 762 822 79 334 283 826 471 612 674 740 135…
Output: 4

Example 2:

Input: 262 476 1 262 68 234 72 164 10 215 32 215 67 230 89 173 42 117 33 202 130 253 85 124 18 65 61 74 131 252 159 194 113 140 22 234 111 257 32 174 28 92 177 261 28 116 115 140 31 32 60 221 80 254 99 143 95 97 151 259 106 193 69 125 42 56 176 198 10 44 107 149 134 233 56 160 89 192 89 97 24 105 151 220 80 99 126 161 40 259 115 175 36 106 95 120 15 197 202 239 136 181 86 253 136 254 32 86 155 162 82 112 227 243 57 237 41 122 171 196 160 233 34 77 149 185 168 183 120 221 155 245 159 224 194 195 86 106 2 208 129 162 95 216 3 204 104 209 202 248 57 149 171 197 70 197 182 213 94 130 71 167 17 134 40 165 37 94 48 241 239 253 44 112 21 185 80 109 9 157 75 257 9 131 142 154 44 88 49 127 11 31 52 260 83 99 56 138 65 241 117 170 57 172 77 205 164 246 236 256 30 149 67 93 9 46 15 183 88 262 139 246 90 224…
Output: 4

Example 3:

Input: 934 2668 1 934 351 901 437 514 544 889 633 685 493 495 2 849 679 795 223 894 32 296 568 599 187 433 73 594 517 599 665 788 289 482 108 190 469 484 84 583 281 460 138 591 899 922 710 884 81 621 275 297 457 763 832 851 767 805 263 478 429 816 258 507 4 321 38 836 36 47 330 373 282 374 421 797 49 232 375 898 70 550 758 924 394 915 898 902 564 676 524 677 132 741 294 803 25 824 851 922 568 805 67 752 119 535 88 680 299 559 256 812 51 222 308 411 208 244 198 855 439 628 616 682 265 305 95 275 67 337 206 589 162 196 209 504 543 587 538 591 93 451 6 742 324 914 351 873 365 824 39 194 268 830 553 631 118 781 422 660 117 247 33 235 322 559 797 930 189 250 102 135 136 220 115 766 401 872 204 556 290 616 140 279 374 442 171 554 499 613 629 868 49 755 603 610 110 295 59 351 190 531 528 810 191 921 614…
Output: 5

Constraints:

1 <= n <= 1863; 0 <= m <= 3726.

Loading...
Test Cases:No test cases
No test cases available.
Lysander and the Fewest Hops - MEDIUM Coding Problem | CodeTikki