CT41380

Gita and the Fewest Hops

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Before the gates of the otter slides of Sleekwater close for winter, Gita must finish the routes ledger - one figure at a time. 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 <= 1763; 0 <= m <= 3526.

Example 1:

Input: 1508 1507 1 1508 366 532 1383 1397 575 823 63 415 288 1132 229 1498 110 586 543 861 197 758 243 1003 696 1096 509 1040 240 357 35 235 367 961 640 742 310 1309 305 1396 21 601 1023 1337 665 1277 726 1385 1041 1257 889 960 776 907 902 1115 754 962 777 1359 969 1330 300 1330 228 1370 789 1055 36 1338 40 668 359 1086 362 783 76 160 206 620 154 560 30 296 467 715 46 1443 1081 1265 973 1455 146 1407 21 723 24 1194 345 970 948 1449 68 618 765 1391 614 797 936 973 1005 1373 1245 1482 90 1368 303 1208 588 1501 1069 1157 732 779 491 891 36 949 602 739 256 920 191 820 403 1416 453 569 1005 1054 701 995 256 770 1324 1342 295 1026 723 1321 533 865 1176 1291 1041 1099 381 864 141 1350 326 940 1019 1297 645 1203 785 1393 40 584 1153 1286 1217 1339 158 1172 319 432 212 309 703 1109 441 793 421 820 414 105…
Output: 7

Example 2:

Input: 256 3277 1 256 5 54 103 224 168 183 177 247 65 236 25 152 39 134 28 202 54 180 19 187 72 125 149 187 5 220 80 156 96 178 83 217 70 208 118 211 171 200 3 217 123 199 1 4 82 219 23 116 67 77 27 193 77 110 21 247 66 96 112 216 25 168 85 248 3 141 177 221 56 242 35 249 16 22 65 212 82 170 68 185 107 203 44 194 17 236 41 205 208 240 190 204 119 193 5 134 27 136 107 156 122 208 18 126 87 108 119 233 127 203 178 251 65 80 35 212 74 256 16 99 12 141 47 111 179 184 105 177 23 79 147 221 45 140 5 194 253 256 152 220 76 137 74 116 98 101 3 21 191 200 58 206 51 151 10 205 26 189 37 87 30 229 62 87 54 205 100 176 36 253 150 209 147 243 135 144 13 149 2 30 18 191 202 236 59 230 130 154 81 204 182 236 66 245 12 16 75 105 4 149 96 214 9 241 83 191 54 158 30 40 78 156 7 48 45 175 131 178 25 206 68 115 20 1…
Output: 2

Example 3:

Input: 1264 2776 1 1264 631 1043 318 664 465 1195 155 713 540 1046 344 760 1004 1156 568 1232 132 1115 306 834 161 672 447 787 222 914 42 173 362 947 190 1049 338 473 267 688 31 704 316 878 531 757 363 405 573 717 88 758 334 496 112 349 226 554 487 1108 903 975 58 596 5 639 416 419 420 592 520 1043 22 352 929 1188 520 603 102 763 489 1090 653 890 28 814 712 1088 1041 1051 909 1067 256 599 17 19 583 585 738 902 472 1053 1081 1100 369 626 130 729 610 1088 8 864 321 999 260 1202 620 888 242 322 1103 1205 360 858 295 1262 412 700 16 993 303 740 531 631 544 1036 1016 1141 385 1236 460 1210 132 803 820 979 129 208 1107 1130 375 1226 514 1063 522 1054 514 936 178 1022 648 938 1154 1184 227 749 359 938 187 376 427 1127 561 1226 317 853 906 1117 745 1088 278 1106 18 363 156 855 502 920 621 1110 94 1235 19…
Output: 6

Constraints:

1 <= n <= 1763; 0 <= m <= 3526.

Loading...
Test Cases:No test cases
No test cases available.
Gita and the Fewest Hops - MEDIUM Coding Problem | CodeTikki