CT56159

Esha's bridges Reckoning

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Morning light hits the jade shrine of Serpentis as Esha unrolls the day's manifest of bridges. The tally will decide the next shipment. 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 <= 3877; 0 <= m <= 7754.

Example 1:

Input: 696 6726 1 696 213 225 141 374 67 268 221 544 236 281 184 281 414 500 472 674 164 270 2 90 395 423 178 294 101 441 241 577 201 494 6 323 348 487 33 579 136 396 582 594 7 661 34 396 523 689 205 445 192 544 404 686 220 432 643 644 532 537 365 555 535 604 603 661 31 560 360 648 558 606 98 110 232 471 126 694 402 574 368 480 536 548 18 560 597 669 539 566 144 507 387 657 37 551 338 651 175 534 62 584 38 476 375 696 170 525 157 610 413 599 72 283 417 510 356 524 640 689 66 269 137 318 542 634 398 409 347 631 6 199 23 369 188 577 64 254 251 409 433 561 15 551 382 573 200 577 302 416 34 234 113 492 78 498 117 584 58 678 303 545 293 435 162 642 403 455 29 564 398 678 57 426 192 651 488 649 535 637 628 656 17 422 30 129 65 664 472 686 120 591 147 338 650 667 61 353 531 679 114 544 19 261 169 214 22…
Output: 3

Example 2:

Input: 2117 4919 1 2117 677 836 1095 1911 108 269 898 1216 78 1066 50 1235 482 712 1970 2069 1197 2031 165 551 398 1240 1224 2020 1016 1283 316 449 374 1501 517 1516 98 982 1249 1736 603 1196 252 1765 621 1388 575 2084 1253 1338 1341 1685 111 953 105 762 30 647 491 997 105 120 781 965 498 897 755 1227 150 237 140 861 1183 1295 761 1162 1311 1369 1342 1999 7 326 337 552 233 515 1080 1668 536 595 1627 1826 586 819 61 1680 276 624 979 1411 709 1902 390 1460 1114 1749 1711 1932 1711 1849 602 1164 429 712 675 1435 1111 1352 622 1350 1082 1197 1437 1543 1645 1732 1044 1572 1279 1527 764 869 688 1940 583 1110 266 1792 96 1715 437 913 523 1186 856 1760 572 1367 1596 1621 447 1687 1029 1700 1339 1775 92 509 436 1453 224 1237 616 1516 1281 1855 1391 2010 1643 1847 1084 1688 402 1446 1541 2037 551 1750 143 …
Output: 6

Example 3:

Input: 2577 2576 1 2577 457 727 1795 1838 382 1615 89 1037 352 2095 1157 1548 472 1593 1560 1756 566 1409 934 1523 1783 1978 1259 1576 1093 2478 1555 1868 329 1082 400 1103 907 1838 480 1172 435 2240 1068 1361 1425 2546 1908 2240 1013 1859 2136 2393 1636 2425 1820 2047 126 1785 2086 2208 257 535 1843 1882 68 2537 448 840 812 1932 1577 1933 951 2052 262 905 2162 2429 573 1268 1322 2084 1513 1665 799 1028 1517 1898 717 2190 1002 1723 1385 2422 745 859 1450 2350 572 695 138 1902 1210 1798 714 734 1106 1898 237 1366 443 2387 241 2391 2132 2505 951 1350 1319 1374 686 1847 1038 1957 1104 1567 1589 1804 348 947 225 524 652 1086 32 846 697 1811 383 1256 125 232 245 577 1278 2009 726 1204 1388 2200 1644 2366 17 2126 69 1166 437 2403 1777 2243 102 1718 436 2393 2418 2450 852 927 637 2544 1129 1757 1061 217…
Output: 12

Constraints:

1 <= n <= 3877; 0 <= m <= 7754.

Loading...
Test Cases:No test cases
No test cases available.
Esha's bridges Reckoning - MEDIUM Coding Problem | CodeTikki