CT53138

Tarun's Fewest Hops Ledger

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Tarun the tallyman watches over the orchard lands of Applerun's stores of tunnels. A careful computation stands between order and chaos. 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 <= 1846; 0 <= m <= 3692.

Example 1:

Input: 1021 3159 1 1021 96 383 341 551 227 466 575 860 58 813 160 329 811 862 84 909 650 799 11 458 102 823 152 948 839 1017 380 907 105 227 449 619 478 531 421 933 161 1011 276 522 759 835 190 775 810 974 154 713 487 541 468 567 531 1010 475 555 555 837 752 953 557 859 560 967 447 923 41 515 87 533 37 668 782 991 726 1019 229 801 636 868 854 995 573 743 46 192 843 966 34 717 146 995 373 453 765 931 529 618 477 940 215 618 463 528 615 664 108 581 451 888 246 472 395 606 729 733 582 769 156 193 355 811 428 457 57 1017 97 349 238 773 350 527 357 960 425 938 481 719 142 817 571 873 888 925 535 807 790 862 16 98 167 455 431 896 388 1015 111 155 338 1005 374 393 968 986 269 561 142 710 473 669 358 684 671 952 373 666 326 666 562 813 272 357 25 741 707 725 419 459 570 649 26 803 788 887 203 701 781 101…
Output: 5

Example 2:

Input: 1085 1239 1 1085 558 575 410 849 165 342 75 191 473 1008 242 1009 475 751 354 729 378 610 55 272 29 488 630 933 271 936 10 1025 45 362 493 820 813 842 362 765 956 1044 625 879 39 256 16 27 998 1085 278 486 212 314 408 937 310 680 795 911 187 299 40 379 513 785 162 185 25 456 801 830 457 727 946 980 311 434 959 1021 85 178 629 847 535 1065 71 85 575 614 502 938 49 464 891 901 335 642 157 612 17 1034 425 602 105 736 700 921 64 142 580 799 191 914 441 744 606 913 939 957 21 753 652 758 112 874 868 977 608 781 153 354 520 866 272 752 398 583 9 973 15 1048 751 1001 703 974 36 768 690 778 843 999 13 678 529 576 556 1065 544 1015 268 596 145 368 295 574 343 453 200 392 468 521 157 337 855 1035 38 49 408 875 184 483 540 754 73 345 954 1010 500 1004 128 1061 476 1008 82 113 24 295 113 720 96 510 10…
Output: 10

Example 3:

Input: 1297 2075 1 1297 522 887 256 976 256 1260 41 339 1 982 546 1074 898 1093 379 579 121 344 48 329 95 1124 508 993 46 1225 540 1267 677 1026 637 738 41 119 908 1024 936 1285 37 346 402 780 290 1169 247 443 983 1267 812 861 370 684 111 305 781 1144 435 446 779 1132 60 431 298 366 259 555 331 540 129 161 155 905 159 701 171 1024 32 179 140 482 245 838 30 580 293 1041 500 524 344 439 43 1094 1088 1172 966 1050 940 1120 404 1143 357 683 1 1164 20 159 101 388 345 454 743 835 687 976 377 777 967 1167 800 1289 605 1183 727 1093 733 1115 381 1054 34 982 1024 1071 555 760 214 1186 89 861 891 1239 53 906 300 419 104 625 775 1055 333 1253 71 1127 253 911 610 987 549 1200 229 334 672 1159 283 1288 38 315 554 981 286 738 4 1080 561 678 73 213 236 352 265 370 634 907 860 1295 305 590 133 518 417 1288 574 1…
Output: 5

Constraints:

1 <= n <= 1846; 0 <= m <= 3692.

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