CT52736

Farhan's Ledger of routes

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Deep in the ember mines of Cindercrag, Farhan 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 <= 2981; 0 <= m <= 5962.

Example 1:

Input: 2646 5339 1 2646 1471 2528 886 1153 390 1854 775 821 1575 1666 319 938 2182 2357 627 1329 79 2130 985 2277 1483 1770 92 628 131 2463 362 703 644 2519 130 648 1081 2558 1739 2012 553 669 385 1022 1596 1759 595 1615 33 2322 1875 2639 1781 1873 749 2312 1709 2394 1145 2262 844 1866 51 972 753 2069 758 2391 50 2148 47 1140 183 1317 303 440 145 751 2026 2591 282 2302 978 1992 45 1102 85 1825 160 1816 1682 2519 639 2364 900 2103 2106 2314 1020 1394 603 2494 1040 2463 589 1518 1462 2032 500 598 440 1069 1813 2298 1729 2453 1532 2559 1 2059 189 2213 2323 2522 659 2452 307 1025 338 1555 15 2458 496 515 555 735 1088 2130 349 1464 1403 2214 1271 1285 2083 2098 860 2466 976 1142 942 2489 667 2420 194 2152 1503 2219 111 164 1047 1505 58 778 2372 2580 739 1401 16 1145 1375 2620 1194 1723 726 994 2212 25…
Output: 5

Example 2:

Input: 181 5039 1 181 125 143 72 111 58 167 6 169 141 154 46 128 60 76 69 139 36 116 109 172 7 26 79 109 125 137 17 172 92 141 10 117 40 158 60 178 10 63 89 162 76 167 50 73 7 39 8 108 163 178 30 168 22 96 30 151 57 119 34 44 17 55 75 167 33 80 33 124 82 116 72 136 81 138 46 47 122 132 118 175 63 136 62 180 23 51 17 47 73 92 65 66 113 114 2 36 47 146 76 78 104 146 30 86 53 88 122 170 23 52 132 151 9 49 93 131 27 151 44 72 81 156 55 111 21 169 6 83 47 72 21 24 11 174 51 139 5 139 42 62 13 103 108 159 43 150 69 150 16 59 114 149 101 165 12 64 10 24 82 129 15 140 108 118 30 126 65 172 89 115 111 145 62 143 85 113 51 153 33 120 79 100 46 111 94 139 32 76 72 153 35 126 90 166 22 25 57 137 118 120 2 118 35 45 164 175 85 108 3 136 37 95 15 130 80 126 39 119 78 170 97 147 1 68 119 175 41 151 83 157 98 15…
Output: 2

Example 3:

Input: 2225 2224 1 2225 836 1831 1568 1651 261 1990 898 938 575 1179 360 1413 765 768 686 2208 1511 2092 427 469 83 2098 971 1373 348 1460 546 1358 235 1333 1735 1843 819 1881 813 2225 799 1530 972 1849 463 1187 1538 1831 513 2224 1193 1721 207 2068 435 2065 345 631 375 871 889 1382 179 1063 371 872 214 1943 1187 2081 1304 1725 146 1261 2201 2221 789 1491 1467 1988 55 403 475 549 530 768 420 1601 434 1231 138 2204 770 1382 1691 1758 834 1573 1142 2026 111 685 73 619 115 847 93 2056 686 2091 321 975 1331 1793 254 2153 248 1893 52 616 1551 2182 1381 2150 353 1772 836 1013 141 996 1080 2004 1493 2154 799 1150 337 489 436 1156 827 1404 689 1298 655 1628 27 1408 247 655 638 1178 737 1195 70 1215 513 1083 1223 1793 1028 2126 820 2211 922 1714 1588 1776 510 1732 515 1599 1072 1159 1682 2073 1540 1958 80…
Output: 12

Constraints:

1 <= n <= 2981; 0 <= m <= 5962.

Loading...
Test Cases:No test cases
No test cases available.
Farhan's Ledger of routes - MEDIUM Coding Problem | CodeTikki