CT52142

Dusky canals Fewest Hops

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

It is audit day at the pine barrens of Needlepoint. Lakshya 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 <= 3937; 0 <= m <= 7874.

Example 1:

Input: 1032 3063 1 1032 365 931 122 229 162 656 67 162 203 884 89 253 197 749 365 907 872 976 137 937 235 1025 181 843 665 943 718 906 389 972 523 929 384 770 389 398 294 964 847 995 127 908 45 90 412 685 325 443 375 558 8 41 302 429 299 589 68 406 182 775 286 762 837 996 219 585 667 726 146 208 60 836 377 590 206 378 132 254 634 679 86 862 52 260 411 655 178 998 26 196 111 629 490 756 799 1032 84 887 25 947 115 896 311 458 307 314 600 613 132 736 660 1023 507 570 88 300 396 504 35 940 396 559 184 812 23 232 712 919 502 733 106 683 4 526 100 209 228 951 208 632 598 717 510 724 682 810 484 822 401 407 243 787 151 337 172 513 28 150 568 676 43 54 89 432 148 531 13 811 194 519 488 841 396 626 165 885 248 398 553 992 421 1001 484 620 528 944 445 817 330 558 163 597 92 1005 362 572 207 356 294 602 10 …
Output: 4

Example 2:

Input: 2924 2923 1 2924 344 1206 1194 1801 593 1056 2219 2767 93 1506 967 2794 1456 1619 410 970 2207 2812 1519 2548 443 1841 1507 2766 842 1989 1561 1771 1706 2891 696 850 217 2466 431 2874 275 2860 1540 2626 227 884 361 760 893 1267 451 2138 1157 1486 44 494 680 1918 803 1595 1701 2815 1188 2448 381 2917 1020 1598 294 1915 576 1096 440 1757 325 2438 614 806 24 1248 378 1618 418 2327 282 1567 818 2147 1840 2203 1504 1724 601 1502 570 1960 1199 2129 1017 1807 1012 2774 1131 1253 41 1726 9 2012 2234 2913 1167 2330 17 1289 660 1397 1606 2025 2192 2218 344 1868 290 2777 940 2101 396 1224 89 1395 1574 2502 836 1908 488 902 1943 2679 361 1025 1339 2362 1300 1787 1500 1854 143 1391 252 2442 264 1146 1004 1293 308 2913 695 769 1090 2634 696 2885 603 1958 794 1914 1942 2853 458 2165 274 1994 1515 2468 52…
Output: 16

Example 3:

Input: 790 3443 1 790 229 232 218 471 138 770 12 63 94 590 63 313 307 668 81 458 14 299 215 656 374 524 225 256 118 527 222 366 416 575 30 537 94 545 192 473 442 696 185 189 107 268 55 163 275 317 263 424 591 693 498 658 64 600 150 439 571 668 168 448 392 595 366 708 136 520 290 728 41 645 381 618 243 470 498 526 84 432 265 610 413 646 67 621 208 392 639 683 92 496 387 629 11 592 164 746 595 652 358 729 364 658 498 586 268 743 155 780 590 672 3 4 33 204 505 566 131 167 387 409 592 712 82 444 20 196 370 529 19 535 162 387 210 413 60 373 295 579 112 128 412 467 310 427 72 522 36 596 239 626 210 610 17 562 371 502 237 563 51 456 184 749 341 723 91 710 250 491 542 760 648 747 428 762 241 432 667 772 235 632 77 676 150 511 449 651 203 504 83 109 289 702 484 553 113 396 198 324 35 590 105 526 164 369 4…
Output: 3

Constraints:

1 <= n <= 3937; 0 <= m <= 7874.

Loading...
Test Cases:No test cases
No test cases available.
Dusky canals Fewest Hops - MEDIUM Coding Problem | CodeTikki