CT30899

The Peculiar canals of Piper

MediumL4 · Loop LordAcceptance: 0.0%XP: 35

The harbor bell rings at the gull cliffs of Screech Point; Piper weighs the day's canals manifests and starts the calculations. 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 <= 1865; 0 <= m <= 3730.

Example 1:

Input: 1483 1482 1 1483 310 1459 585 614 276 918 61 650 168 577 16 416 210 1354 38 1274 489 624 285 533 52 604 106 575 1057 1177 995 1450 343 1088 1039 1247 530 778 1138 1298 559 995 694 1141 380 561 307 326 817 1155 124 1182 287 833 241 444 202 1034 544 1126 701 1343 718 1306 275 387 305 449 278 1046 245 838 624 1026 644 847 468 646 1179 1384 54 595 1082 1363 289 554 1089 1398 951 1033 193 244 786 994 457 748 531 687 253 641 467 992 216 987 936 1112 457 1346 318 497 255 939 570 689 349 1226 1096 1111 304 920 444 1130 1225 1422 252 309 211 642 248 1128 114 331 231 938 5 1327 922 1398 997 1338 195 1161 837 1068 1042 1059 615 759 627 1007 652 851 734 883 177 1387 196 1403 433 947 103 510 991 1387 760 1215 688 1121 379 853 799 962 636 1071 297 1364 389 562 161 984 756 1375 390 1422 75 1107 1052 1210…
Output: 8

Example 2:

Input: 11 55 1 11 5 9 9 11 6 7 4 9 2 11 4 11 4 7 1 7 7 9 3 5 2 5 1 2 2 10 2 4 6 9 4 6 4 8 10 11 7 10 5 8 5 7 8 9 7 11 1 11 8 11 3 8 1 8 4 10 2 7 6 11 1 9 3 7 1 4 8 10 7 8 3 10 2 3 5 6 6 10 3 4 3 6 2 9 4 5 1 10 2 6 3 9 1 3 1 6 1 5 3 11 6 8 2 8 9 10 5 11 5 10
Output: 1

Example 3:

Input: 918 3342 1 918 857 892 347 791 296 738 512 596 602 731 165 891 577 598 228 918 167 696 440 711 16 870 388 771 2 454 94 732 301 512 430 881 247 651 382 429 412 500 108 272 335 739 87 776 4 782 361 912 45 231 223 319 587 765 158 598 248 406 620 697 506 836 540 585 371 635 259 876 208 317 43 111 783 799 694 705 157 590 484 741 576 715 337 785 590 864 607 821 57 552 418 724 801 892 69 759 127 639 376 404 592 846 474 559 861 904 121 264 391 750 145 840 295 307 388 724 172 745 37 78 304 643 228 709 25 562 72 522 452 817 172 813 629 824 874 901 48 666 338 565 695 720 172 542 13 357 49 720 202 883 569 578 20 656 16 620 224 793 455 796 799 810 87 442 277 678 139 665 270 776 339 431 418 753 283 300 211 457 865 873 244 362 370 481 779 908 349 902 220 891 30 618 97 606 599 637 243 786 237 358 180 188 …
Output: 3

Constraints:

1 <= n <= 1865; 0 <= m <= 3730.

Loading...
Test Cases:No test cases
No test cases available.
The Peculiar canals of Piper - MEDIUM Coding Problem | CodeTikki