CT45365

The Fewest Hops of Whitestone

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

The council of the alabaster quarry of Whitestone pays by the answer, and Tara intends to earn it. First: the full register of routes. 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 <= 2962; 0 <= m <= 5924.

Example 1:

Input: 1576 1575 1 1576 907 1252 77 1197 151 362 270 843 1489 1521 705 1381 207 1199 1265 1404 1039 1353 47 771 430 1061 729 891 121 845 661 1177 1331 1522 679 707 515 709 54 1494 895 1125 788 1515 519 767 87 257 656 1201 467 822 663 1536 51 1197 128 1338 359 1195 627 1466 862 1437 254 454 114 680 845 1322 393 559 680 1466 68 282 778 1491 353 1053 810 1242 357 443 531 1083 265 788 528 1137 930 1326 805 1230 168 603 921 1250 16 1351 902 1441 215 857 16 855 15 1477 529 962 369 1323 18 1120 264 1406 553 1388 878 1199 973 1243 1028 1294 775 924 407 721 281 1333 789 1382 630 814 1010 1047 153 825 600 1099 370 1141 213 1253 293 661 484 1482 829 1088 1407 1499 731 931 726 1546 62 1020 155 1461 597 1405 270 832 278 1493 142 1114 616 807 410 1199 931 1110 31 699 535 1472 782 1336 1130 1511 27 619 257 492 …
Output: 8

Example 2:

Input: 1194 1193 1 1194 977 1170 717 824 901 1109 295 296 161 868 129 434 350 765 6 710 580 1076 171 1161 122 649 343 1149 978 1119 664 972 351 489 290 745 26 275 503 847 62 960 944 1133 557 689 150 1085 788 1120 807 885 274 847 112 1084 954 1135 788 839 502 848 541 581 882 888 33 788 197 582 11 408 343 828 119 838 116 278 190 521 352 1095 194 336 703 956 205 467 669 1177 42 656 23 587 303 416 131 263 145 195 246 584 289 842 993 1009 177 768 1018 1113 973 1095 73 1022 664 1003 79 633 194 798 932 1172 643 717 855 991 773 979 953 1160 698 1151 468 820 240 510 669 974 401 1106 295 784 577 863 29 503 51 1039 1075 1127 423 756 124 205 371 811 454 757 617 926 261 267 540 816 132 324 44 1112 150 868 198 199 961 1096 419 972 92 377 891 897 345 725 212 1097 245 892 76 293 456 772 213 246 530 663 39 985 23…
Output: 16

Example 3:

Input: 1916 5313 1 1916 10 767 180 681 1234 1539 786 1579 1445 1901 1541 1857 1132 1251 823 1880 471 1670 683 1075 533 1411 669 1547 174 1881 1487 1714 244 720 20 190 1420 1879 1074 1167 696 794 962 1479 447 1688 1179 1801 399 1553 130 603 69 242 432 1166 125 1374 201 399 394 772 440 1289 1543 1691 174 535 1329 1709 216 635 856 1904 113 1239 39 497 256 801 1389 1462 477 1677 748 1710 717 900 214 1584 1612 1862 1621 1697 74 559 177 1644 593 1299 83 1269 979 1630 878 1375 488 1102 355 529 94 337 1065 1673 245 1120 591 1908 204 1827 674 1402 343 1218 77 1018 1634 1844 461 1871 438 742 1217 1820 364 1164 1021 1780 6 605 575 956 939 957 53 888 200 749 576 978 198 481 904 1787 761 1685 1021 1541 1020 1852 409 510 1426 1806 1045 1901 447 556 174 1198 202 1161 418 659 1241 1475 1025 1702 543 1435 557 137…
Output: 4

Constraints:

1 <= n <= 2962; 0 <= m <= 5924.

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