CT39534

Odin's Fewest Hops Ledger

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

The harbor bell rings at the canyon post of Redrock; Odin weighs the day's routes 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 <= 1717; 0 <= m <= 3434.

Example 1:

Input: 611 2320 1 611 63 113 419 560 82 257 146 200 305 406 164 377 326 508 18 84 418 433 283 558 298 405 369 465 74 129 43 224 170 431 43 501 125 444 188 283 229 432 134 439 310 438 111 591 262 285 149 271 378 511 504 531 176 449 348 547 307 388 35 373 270 274 148 247 89 282 170 339 241 254 374 596 275 410 278 321 385 578 184 501 105 546 256 448 334 368 247 507 193 381 305 336 403 537 174 587 149 237 171 179 234 575 46 478 283 367 20 571 32 364 67 124 191 424 142 243 105 322 287 331 478 511 20 143 135 319 94 162 215 590 246 349 358 560 257 350 247 543 176 493 277 486 445 516 102 535 11 372 425 571 97 543 558 605 248 539 246 444 99 101 131 422 141 146 407 557 193 557 194 404 39 168 127 267 144 556 294 307 128 603 116 426 155 303 16 384 389 607 226 361 483 524 430 527 484 517 249 473 73 96 294 606…
Output: 4

Example 2:

Input: 1419 1419 1 1419 788 900 12 964 736 1411 506 1187 43 504 668 822 369 562 993 1082 458 1174 89 1268 671 1369 534 1024 448 1242 337 626 834 1046 416 968 997 1196 248 854 330 1146 593 1032 275 1276 226 743 61 1043 725 1196 234 801 1198 1296 250 453 756 824 462 1379 598 947 278 657 1295 1372 460 936 21 1402 546 870 29 543 713 950 291 314 892 1081 816 1190 570 1144 171 1267 436 1118 756 924 452 1403 422 1366 29 67 323 696 316 956 625 1096 885 1366 240 1364 169 531 175 641 400 468 57 577 3 979 62 1244 404 1270 726 1173 92 296 157 487 103 288 1204 1360 334 1417 461 1396 862 1322 610 674 211 689 345 437 469 824 271 418 666 1033 113 570 378 551 447 1043 462 645 70 979 450 777 376 923 696 1337 1020 1046 827 1041 540 737 691 718 230 537 165 795 1033 1312 957 1216 357 1213 593 1023 272 1230 462 989 26…
Output: 10

Example 3:

Input: 452 3081 1 452 229 248 133 150 230 393 19 250 166 246 45 88 133 376 118 250 204 408 257 449 133 407 238 393 187 325 304 415 124 221 36 438 315 375 2 113 316 325 268 299 414 434 51 347 49 298 53 185 150 239 391 431 245 355 96 242 37 364 380 384 289 366 190 432 213 331 148 259 334 415 24 149 108 334 331 392 35 221 149 217 292 382 213 417 120 346 17 315 86 248 37 375 203 274 215 421 297 409 123 178 11 228 132 401 215 265 15 199 60 341 52 184 176 297 255 451 273 346 185 298 23 239 202 313 197 338 14 235 149 341 52 363 89 113 101 219 117 164 227 343 100 143 85 355 45 272 143 424 44 94 330 438 143 349 80 271 135 343 6 383 170 352 255 284 261 265 6 301 416 445 189 399 378 408 109 316 92 246 188 199 52 128 152 372 159 391 33 240 184 357 89 116 101 271 366 428 227 325 268 348 133 223 83 295 32 343 …
Output: 3

Constraints:

1 <= n <= 1717; 0 <= m <= 3434.

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