CT51937

Last routes of Tinker

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Deep in the saffron fields of Marigold Row, Tinker studies rows of routes entries. One clean number will settle the guild's oldest argument. 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 <= 3244; 0 <= m <= 6488.

Example 1:

Input: 2939 4169 1 2939 833 1368 744 1190 1740 2286 1653 2332 1327 1885 877 1249 724 2013 339 845 1362 2554 1249 2642 1677 2787 179 2398 881 2023 509 2712 897 1793 1012 2490 1434 2696 1603 2869 685 2730 1166 2689 1120 2667 261 2578 2089 2256 796 1114 1378 2485 1433 2274 94 812 1255 1361 449 2463 1535 1837 1026 1960 1769 2582 831 1655 328 584 804 1850 363 524 164 374 662 2190 67 1851 2595 2742 743 1228 688 2088 1056 1274 672 1906 1037 2441 858 1492 2286 2287 576 2932 685 2075 1183 1332 29 75 213 473 443 1893 404 1938 1899 2505 754 2407 885 2009 358 1610 1174 1945 487 2177 1690 2540 77 245 1953 2919 2545 2890 417 1452 2270 2825 2132 2690 1101 1206 1714 1830 1490 1604 1340 1459 1331 2778 1330 1962 1533 1877 1833 2147 1409 2662 364 2460 272 2006 2762 2919 2488 2836 1704 2479 677 1553 1160 1371 165 27…
Output: 6

Example 2:

Input: 1895 6166 1 1895 1128 1205 848 1479 555 873 368 1767 1536 1856 158 769 115 880 421 813 1243 1260 713 1749 313 901 218 798 375 840 172 640 1081 1536 113 1583 968 1893 1237 1298 341 1001 957 1554 1328 1559 127 1356 973 1265 72 1802 124 1679 506 1229 228 592 678 1269 484 1080 54 969 1558 1713 657 1788 180 409 1038 1739 951 1221 88 1364 489 1364 802 1007 1312 1751 705 1402 20 1190 11 1270 919 1588 45 643 747 1470 115 1651 30 1108 507 849 714 1411 258 583 342 958 415 1551 745 1727 497 969 186 704 501 1716 637 1187 1548 1756 179 1082 230 1669 470 1063 958 983 916 1612 416 1132 443 762 977 1651 230 1500 792 1756 727 1112 39 1603 407 910 572 1873 75 1207 959 1796 601 1423 328 1802 1155 1238 115 1275 864 977 480 1759 798 1042 213 404 1126 1713 47 234 1747 1829 467 1502 82 558 308 406 1366 1773 307 …
Output: 4

Example 3:

Input: 2541 2540 1 2541 135 2424 769 1478 741 1723 334 902 2056 2227 194 645 1009 1625 56 2096 245 569 1419 2104 1902 2415 298 2054 747 864 215 1250 334 2246 70 1345 1416 1451 508 2512 1317 1371 563 1207 938 1633 1546 2483 143 2287 210 329 1695 2228 57 1811 1037 2302 855 2004 143 413 230 1656 162 820 112 447 115 1659 688 1073 19 60 10 1535 2107 2506 138 2368 1652 2207 784 1687 575 2063 1666 2233 33 873 940 2282 984 2506 2123 2349 54 995 1677 2068 2072 2354 522 2077 1562 2187 889 2493 1020 1889 1010 1373 1853 2306 790 2108 766 786 1435 2293 2274 2294 731 1238 1383 2111 307 2104 1671 2422 554 1486 1806 2291 837 1837 385 684 150 1060 1889 2520 1661 1677 1209 2162 1072 2339 649 1530 1142 2391 426 1878 334 2014 1103 2232 1298 2127 191 458 1081 1365 533 2480 843 1974 510 1201 1383 2473 1080 2298 550 11…
Output: 13

Constraints:

1 <= n <= 3244; 0 <= m <= 6488.

Loading...
Test Cases:No test cases
No test cases available.
Last routes of Tinker - MEDIUM Coding Problem | CodeTikki