CT37523

Opal and the Crimson canals

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

It is audit day at the floating docks of Skyharbor. Opal spreads the canals records across the table and picks up a sharp pencil. 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 <= 2762; 0 <= m <= 5524.

Example 1:

Input: 77 2926 1 77 30 44 30 52 59 64 44 53 33 61 34 36 36 68 1 24 19 58 43 64 42 76 24 44 7 17 37 47 36 39 42 66 7 16 4 11 63 66 3 76 33 43 4 45 28 50 37 50 59 71 69 75 5 8 36 72 7 47 23 58 17 20 11 15 18 65 12 49 20 52 6 26 15 48 18 72 3 73 2 41 5 31 2 16 50 76 38 76 70 75 24 37 20 22 45 54 39 62 19 66 16 24 32 33 5 74 33 73 37 75 42 58 37 59 31 33 14 46 55 58 17 50 11 32 75 77 1 47 33 48 9 41 22 57 20 36 13 47 2 34 34 70 16 37 56 69 29 43 28 30 37 42 35 39 26 51 55 75 2 30 48 64 12 69 47 62 41 60 41 62 10 47 3 67 16 62 57 76 22 23 51 71 4 37 8 24 3 36 56 74 6 32 56 72 2 76 35 48 33 50 10 40 64 67 46 47 24 64 19 41 56 63 23 62 34 61 26 48 37 54 8 63 44 61 36 48 64 69 52 77 37 61 13 68 33 54 14 47 13 71 37 71 7 28 15 44 2 25 29 32 41 45 4 24 8 69 16 69 14 61 3 28 45 51 27 70 7 44 22 30 18 19 15 …
Output: 1

Example 2:

Input: 2277 2276 1 2277 44 83 1747 1915 1045 1848 144 602 110 376 373 2203 369 912 1488 1571 1356 1549 132 633 645 1604 503 2081 422 712 274 1477 1207 1324 124 1706 854 2153 918 1090 296 2127 502 1172 67 569 539 1525 1146 2234 292 1177 1029 1769 1768 1810 1009 1561 572 1545 423 780 1088 1597 524 751 722 2238 215 1245 426 2081 637 2204 497 1979 342 1646 1533 2076 252 1383 576 1745 827 1462 274 480 279 1676 1378 2030 808 2075 526 1714 209 2154 1842 2020 1573 1940 1551 2151 501 1292 412 624 928 2180 1298 1668 398 987 629 1997 181 1878 1048 1451 1072 1234 1633 1937 263 1465 147 525 1240 2025 226 951 263 612 774 1082 611 1773 1380 1573 1235 1979 591 1664 203 1793 93 1295 1184 1546 296 1129 1720 2057 565 1122 17 848 926 1040 1094 1657 1220 1337 1020 1266 1349 2134 1130 1460 79 1379 130 1423 124 688 98 …
Output: 16

Example 3:

Input: 2533 4770 1 2533 1324 2252 945 2454 502 2185 1255 2259 781 961 1675 2165 239 2032 623 1583 555 2517 198 548 507 1942 274 919 844 979 815 1411 55 845 212 1795 1190 2460 1376 1793 814 2045 1701 1950 879 1759 346 1881 482 657 546 1490 456 1991 356 2503 2200 2308 479 996 1472 2390 1890 2182 195 1247 1005 1070 3 1684 511 2316 2001 2499 1146 1956 1329 1886 517 1297 361 1125 1429 2236 249 1806 51 1775 23 207 542 2398 140 486 194 1736 430 528 664 1322 96 156 158 1812 187 2416 1237 1940 223 1417 887 1687 216 1633 1757 1979 1122 1418 1235 1548 595 1334 590 1674 77 1446 1220 1596 1109 1164 1012 1219 163 935 71 303 77 1854 60 944 584 1303 943 1409 845 1412 1657 1885 672 1494 2433 2477 139 2309 94 896 995 2242 523 2332 332 2015 652 2314 1306 1672 66 303 350 1092 610 758 1186 2171 1914 1921 1274 2342 90…
Output: 6

Constraints:

1 <= n <= 2762; 0 <= m <= 5524.

Loading...
Test Cases:No test cases
No test cases available.
Opal and the Crimson canals - MEDIUM Coding Problem | CodeTikki