CT52977

The Fewest Hops at Rootwater

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Deep in the mangrove channels of Rootwater, Tanya studies rows of routes entries. One clean number will settle the guild's oldest argument. 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 <= 2676; 0 <= m <= 5352.

Example 1:

Input: 1547 1546 1 1547 588 1457 588 1509 1267 1347 746 1475 884 1537 78 571 1283 1304 1012 1518 350 704 526 1143 951 1150 509 793 1367 1521 603 1230 618 985 466 1462 1173 1378 1000 1121 157 1448 558 1361 331 909 233 1454 301 354 466 1166 330 1390 392 495 985 1398 1075 1094 188 386 1000 1218 920 1071 871 1491 443 1227 370 1248 195 234 223 773 686 691 145 154 170 229 828 1314 93 423 1431 1532 468 1137 56 1467 470 773 78 1039 9 473 308 1446 374 1504 745 1002 331 1094 281 1273 269 1364 964 1169 1278 1373 1020 1334 458 796 161 305 1061 1479 846 903 773 783 945 1031 760 1109 1173 1228 4 225 902 963 440 1264 589 593 660 896 141 273 101 545 599 952 30 1029 397 506 662 1546 35 591 778 1212 1158 1180 336 541 80 555 681 1007 1081 1084 437 1127 420 861 233 1165 1213 1355 420 1159 277 1373 938 1288 286 919 1…
Output: 19

Example 2:

Input: 441 2649 1 441 137 235 279 350 39 116 32 285 50 82 256 360 252 305 235 400 28 322 10 261 24 223 110 399 98 381 191 268 236 353 194 246 63 146 83 371 128 247 256 261 88 260 34 209 142 231 141 239 81 88 69 327 157 380 99 241 81 103 69 209 6 80 156 367 249 394 145 319 48 239 45 93 76 441 151 412 200 308 28 427 147 398 137 441 111 325 172 369 110 247 125 226 126 346 94 374 64 370 217 284 258 278 11 397 44 160 133 275 50 191 108 287 159 353 61 192 71 363 59 349 344 372 8 354 122 138 65 416 291 438 107 213 160 264 228 440 257 374 123 207 102 247 95 322 180 216 64 180 112 415 150 263 15 429 362 397 305 312 107 196 150 332 53 424 94 192 289 337 46 285 93 270 98 99 19 192 196 349 303 362 55 339 9 41 332 441 244 302 71 335 161 356 176 242 287 436 29 59 27 374 2 124 107 438 4 49 76 179 344 356 50 375…
Output: 3

Example 3:

Input: 1134 1258 1 1134 522 530 45 292 593 750 283 806 59 1005 893 1127 792 832 173 822 737 1111 127 522 347 936 591 918 784 1121 606 781 455 555 217 464 296 814 328 561 140 772 221 711 514 877 630 1111 4 1026 33 436 931 1111 220 707 1002 1005 40 573 858 962 209 746 554 1084 159 838 240 882 966 1101 61 883 41 522 29 771 610 841 501 599 161 805 256 564 408 925 358 1132 68 1105 599 1088 71 151 228 576 26 278 773 889 90 909 242 660 156 268 839 1019 92 1090 32 1080 477 937 28 854 556 809 582 674 102 648 524 802 532 601 83 1125 878 1052 133 521 498 696 3 12 31 544 127 730 131 391 137 855 1099 1112 656 873 632 1031 400 953 207 750 16 573 718 911 863 907 606 789 945 1056 330 670 592 1005 578 903 104 137 157 698 623 999 573 1111 26 517 511 940 868 876 510 814 748 798 971 982 649 760 154 1097 159 602 431 …
Output: 12

Constraints:

1 <= n <= 2676; 0 <= m <= 5352.

Loading...
Test Cases:No test cases
No test cases available.
The Fewest Hops at Rootwater - MEDIUM Coding Problem | CodeTikki