CT31203

The Fewest Hops of Lodebarrow

MediumL4 · Loop LordAcceptance: 0.0%XP: 35

The harbor bell rings at the silver mines of Lodebarrow; Kate weighs the day's tunnels manifests and starts the calculations. 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 <= 1735; 0 <= m <= 3470.

Example 1:

Input: 542 1609 1 542 96 515 32 243 262 364 186 201 51 534 114 418 23 384 15 241 117 367 66 403 375 540 97 312 263 280 62 423 78 510 128 360 22 424 34 271 297 302 229 363 218 350 180 487 151 479 318 404 193 447 473 483 58 258 277 412 196 526 301 407 277 378 19 520 126 245 2 205 154 510 121 509 223 389 13 165 257 356 83 320 105 187 263 296 53 278 58 168 49 290 154 286 116 267 457 521 362 511 235 315 198 532 144 390 119 192 238 510 132 383 294 387 55 410 274 354 49 249 16 74 27 178 38 217 182 493 260 378 151 508 174 276 3 274 332 536 140 369 27 522 237 483 213 438 152 529 90 308 10 51 111 203 482 520 15 212 125 483 19 325 387 412 418 444 18 384 106 314 198 465 35 270 104 307 70 290 422 449 252 469 7 25 193 206 26 40 351 526 248 402 335 506 336 411 237 538 348 383 300 501 37 244 15 49 245 519 61 389…
Output: 2

Example 2:

Input: 834 952 1 834 332 379 246 832 103 694 1 173 26 569 407 411 280 284 10 29 337 380 590 693 98 163 90 641 25 437 258 595 103 326 178 379 369 472 56 371 427 681 483 655 218 416 7 554 218 674 18 502 153 706 70 589 218 294 470 597 266 731 279 479 502 529 59 694 334 519 118 705 550 815 409 481 197 201 10 558 424 462 240 814 306 442 166 353 161 404 277 792 42 601 10 801 426 547 146 473 212 358 182 789 87 280 138 379 251 434 117 121 515 674 210 500 558 811 160 660 441 658 169 690 303 453 9 759 398 579 66 783 466 591 165 647 209 660 471 598 137 764 228 480 318 697 718 762 621 721 471 766 1 141 308 765 169 319 91 445 249 328 373 550 643 673 97 138 122 770 493 707 653 668 7 446 368 830 49 229 634 721 93 104 223 719 276 308 789 806 58 482 356 745 374 589 421 474 489 825 180 646 298 801 447 453 407 670 …
Output: 9

Example 3:

Input: 379 2394 1 379 15 240 37 182 134 278 15 51 16 96 219 375 91 192 136 290 279 358 122 144 193 366 100 216 11 177 56 306 55 82 60 128 59 372 55 238 121 324 332 347 46 179 24 218 42 296 217 283 142 145 265 281 2 155 42 298 114 303 200 246 165 317 131 334 141 146 52 294 208 253 106 278 80 124 13 100 137 172 39 240 303 338 300 307 270 302 26 96 133 183 62 365 21 367 88 199 272 273 17 153 73 117 162 362 59 309 280 281 311 346 183 375 246 288 80 244 154 197 296 371 107 211 113 378 111 284 157 184 136 352 109 229 233 340 8 19 94 177 121 185 150 298 9 169 26 284 146 180 25 57 28 322 70 133 97 236 69 281 44 211 198 298 111 205 65 188 111 379 214 232 109 128 30 254 61 230 162 258 57 327 7 9 156 355 129 367 95 171 242 349 40 80 66 259 215 260 116 171 45 103 34 100 235 309 188 335 300 375 194 279 190 24…
Output: 3

Constraints:

1 <= n <= 1735; 0 <= m <= 3470.

Loading...
Test Cases:No test cases
No test cases available.
The Fewest Hops of Lodebarrow - MEDIUM Coding Problem | CodeTikki