CT35477

Bram's Fewest Hops Ledger

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

At the beacon hill of Lantern Tor, Bram records each tunnels in a worn leather ledger. The guild wants answers, not guesses. 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 <= 1792; 0 <= m <= 3584.

Example 1:

Input: 401 400 1 401 98 170 124 209 177 335 54 266 14 125 356 377 16 266 26 39 231 247 38 109 293 374 161 376 3 319 115 390 326 375 161 268 50 235 10 316 108 299 335 372 165 322 66 142 245 364 63 123 181 261 95 112 110 229 194 349 19 190 77 395 189 288 108 119 59 257 128 155 21 386 215 369 35 147 6 103 229 296 277 287 291 342 152 399 67 95 212 329 204 398 201 220 115 333 27 113 322 354 259 298 323 377 132 153 83 88 73 401 241 371 169 353 18 224 126 143 218 320 196 381 171 328 25 366 10 102 10 234 147 277 25 139 101 275 203 328 140 286 51 280 215 238 124 215 319 379 329 392 8 173 283 319 47 174 81 202 65 244 266 324 20 131 72 253 108 125 55 126 189 376 62 159 166 299 75 137 80 283 179 200 213 338 113 180 1 163 240 381 129 233 7 32 142 309 189 334 181 281 1 125 49 228 100 183 57 142 185 240 15 315 …
Output: 8

Example 2:

Input: 1039 3163 1 1039 67 89 686 821 314 1020 799 816 365 807 410 532 83 584 524 684 14 794 864 972 275 807 321 482 210 538 673 957 909 934 233 254 818 921 489 549 304 849 175 540 306 547 875 926 239 571 1 580 277 808 146 628 346 1039 199 1000 387 506 207 710 41 603 5 334 141 163 275 502 726 895 796 882 194 973 332 972 37 863 675 968 979 1020 354 619 740 932 106 782 5 97 345 481 202 366 307 952 373 1014 766 939 305 873 595 877 114 224 343 713 273 854 433 837 435 503 79 926 454 650 65 271 352 532 711 841 149 484 95 740 298 1015 298 719 254 834 105 178 224 443 406 1014 85 209 651 781 667 678 168 501 438 582 429 507 82 447 440 936 591 629 200 763 181 699 32 124 738 821 596 681 355 819 619 931 938 972 211 820 69 934 449 610 818 907 69 850 64 690 269 895 229 255 228 645 636 850 47 630 613 660 316 554…
Output: 3

Example 3:

Input: 289 1725 1 289 21 129 14 128 29 278 246 249 97 229 246 285 11 114 109 126 106 214 48 61 4 99 105 231 235 236 112 238 3 206 174 193 129 182 13 269 108 202 141 176 68 133 107 218 180 198 79 94 83 138 71 102 229 265 20 202 98 153 144 224 105 264 122 161 74 176 97 271 124 188 177 189 165 215 7 41 155 268 39 235 9 131 69 184 2 238 5 38 101 270 170 251 24 122 51 227 193 283 209 231 62 183 41 77 31 205 88 120 172 174 173 257 28 56 149 251 147 268 43 83 13 238 217 288 230 279 275 283 149 276 69 272 71 207 10 144 139 279 163 206 128 133 80 271 184 204 87 184 77 148 201 281 22 281 16 43 30 55 18 45 47 119 166 268 197 262 113 127 72 254 39 276 85 121 18 148 28 237 156 231 11 74 124 138 108 132 189 260 53 162 8 46 209 254 64 124 4 141 97 272 33 75 161 173 168 269 190 214 242 247 11 162 22 118 28 268 3…
Output: 2

Constraints:

1 <= n <= 1792; 0 <= m <= 3584.

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