CT36243

The Glimmerfell Fewest Hops

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Every season at the quartz ridge of Glimmerfell, someone must balance the workshop's books. This year the task falls to Forester, armed only with the bridges register. 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 <= 1265; 0 <= m <= 2530.

Example 1:

Input: 979 1759 1 979 28 582 25 450 2 525 568 819 489 927 172 174 73 858 73 856 493 789 66 410 159 450 81 133 732 945 18 521 33 562 218 710 309 381 19 952 135 751 310 504 258 260 301 732 54 714 15 18 788 864 246 759 506 630 334 826 168 938 105 480 201 958 154 622 270 527 112 881 357 753 50 711 61 125 589 786 350 518 429 856 274 525 80 940 128 164 99 220 56 400 344 693 24 107 50 306 33 812 232 599 646 754 199 274 51 958 211 754 577 666 282 857 281 782 281 473 250 524 352 931 103 946 180 676 350 911 834 930 393 402 277 482 327 901 91 335 631 746 375 749 226 444 15 671 270 494 348 510 179 527 626 802 40 348 838 900 4 920 370 767 341 574 271 490 394 445 233 270 267 413 232 864 130 454 113 625 226 922 98 218 957 968 496 591 495 686 593 979 420 910 319 681 62 872 509 938 114 371 589 617 32 68 34 77 403…
Output: 6

Example 2:

Input: 991 1406 1 991 530 759 371 632 189 767 319 761 117 842 451 936 803 846 425 806 314 567 164 613 622 661 64 441 553 729 784 862 452 738 204 737 32 541 99 144 836 965 233 585 514 625 127 676 50 946 502 801 89 235 588 846 374 503 10 478 39 862 153 537 282 923 732 916 494 674 837 937 307 950 824 873 276 695 456 844 156 600 230 373 418 906 566 579 642 691 373 799 438 878 423 492 578 759 134 972 750 765 707 797 22 545 656 926 708 863 257 525 517 762 155 470 59 850 418 828 343 859 438 665 44 673 6 101 475 939 640 886 144 839 706 846 97 387 130 307 75 160 610 913 362 656 580 643 519 887 676 776 400 504 450 672 132 519 184 380 202 602 716 845 157 754 188 614 420 596 76 412 55 707 238 940 489 580 307 645 657 745 371 594 234 674 142 480 620 941 238 466 393 667 678 938 264 379 114 281 118 376 118 488 4…
Output: 7

Example 3:

Input: 662 752 1 662 446 590 87 178 23 540 255 464 63 157 382 435 262 275 72 115 84 172 145 459 95 469 278 661 236 581 104 305 53 490 36 523 233 600 574 593 174 234 364 454 223 305 281 457 72 573 32 255 243 523 306 529 120 456 128 294 307 621 173 582 142 496 410 582 99 563 94 375 146 475 89 439 517 604 466 597 39 127 145 300 429 538 526 578 26 272 166 222 255 264 84 273 306 346 419 439 397 648 124 138 26 558 199 493 60 205 276 295 529 576 187 441 112 506 545 644 175 370 542 588 28 605 484 631 385 424 262 499 30 148 383 657 416 442 530 580 26 180 227 271 277 594 242 472 227 552 22 633 184 609 350 378 253 662 591 655 45 85 435 524 150 661 47 95 327 562 28 457 397 661 492 627 320 323 492 592 138 589 256 483 72 583 167 468 525 539 268 324 359 604 232 373 52 75 33 123 467 539 516 621 534 580 313 532 1…
Output: 9

Constraints:

1 <= n <= 1265; 0 <= m <= 2530.

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