CT39189

Theo's Shimmering Ledger

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Before the gates of the pearl fisheries of Nacre Bay close for winter, Theo must finish the routes ledger - one figure at a time. 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 <= 2034; 0 <= m <= 4068.

Example 1:

Input: 1514 1513 1 1514 601 772 976 1091 3 1023 792 1043 81 245 475 1274 150 1314 130 1330 228 312 100 1370 849 1013 81 206 308 1189 229 370 70 487 1107 1468 549 939 132 266 664 736 1167 1260 214 323 431 1500 442 909 102 107 773 875 161 502 467 1032 882 1445 72 491 546 691 647 1241 458 1016 570 1307 623 1257 490 752 632 690 55 408 854 1059 33 309 352 841 749 1490 656 969 677 977 568 1191 124 1235 619 1059 914 1458 1072 1128 19 1116 112 1109 904 1301 565 683 56 1205 238 985 579 1036 839 1487 746 1269 660 720 481 1361 389 517 389 782 102 843 59 620 404 1043 223 1224 8 81 186 266 1209 1514 272 363 1244 1468 15 799 532 597 1015 1243 663 1475 228 379 130 1098 200 584 196 1068 1368 1391 314 708 586 710 118 298 1106 1271 194 260 823 1471 678 886 533 1253 89 587 1234 1274 341 457 1186 1512 263 1137 468 1…
Output: 10

Example 2:

Input: 1358 1357 1 1358 1122 1312 276 466 176 1223 713 768 346 756 56 411 85 347 106 1337 200 729 32 133 31 727 1035 1134 721 1026 310 931 888 1150 336 1318 67 647 82 556 736 1203 904 992 588 1009 1230 1263 157 981 279 1193 577 972 31 455 264 982 20 1075 27 190 125 178 620 1149 340 467 207 898 83 759 112 1190 852 1274 1040 1236 1087 1193 871 892 537 1204 784 964 1003 1015 207 404 313 886 414 742 359 653 817 1122 949 1096 34 1066 652 1130 794 1239 182 704 984 1012 588 806 736 823 78 732 360 1220 490 1151 762 1147 441 852 727 1283 701 703 867 1299 406 897 723 909 367 1059 70 994 104 1008 868 1086 665 672 646 1190 953 1039 683 718 778 786 1013 1242 810 1286 409 582 817 1296 635 1346 430 443 153 980 255 1010 339 1053 793 946 1012 1285 473 697 742 1147 86 855 1327 1349 1047 1048 1121 1172 206 640 411 …
Output: 11

Example 3:

Input: 1944 1943 1 1944 775 822 8 1646 1178 1241 70 1134 1291 1681 1400 1645 779 1393 367 1695 475 1663 617 1421 1228 1501 655 1713 1401 1868 674 1767 1152 1304 729 1000 638 1224 848 1227 925 1623 264 1627 541 1712 107 586 779 1321 665 1606 517 1074 972 1866 446 1050 15 306 632 818 57 1889 1707 1792 590 1296 20 966 314 1431 503 1222 873 1422 894 1671 1334 1636 170 1935 67 1402 36 437 147 1326 143 698 163 1538 1318 1757 1207 1636 1440 1453 1177 1472 382 1368 146 284 606 1300 748 1451 540 820 256 441 875 1467 266 411 726 1327 845 1768 701 1098 1037 1938 63 1654 625 1801 351 434 1009 1444 583 1149 185 1254 1340 1587 990 1397 39 1804 201 397 181 548 658 1590 455 691 535 1864 859 1205 1083 1656 63 1795 180 193 1086 1611 1562 1942 632 1715 356 656 391 978 607 1442 752 1506 472 1577 873 1800 315 1538 52…
Output: 9

Constraints:

1 <= n <= 2034; 0 <= m <= 4068.

Loading...
Test Cases:No test cases
No test cases available.