CT53822

Aria's Amber Ledger

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Caravans arrive at the moonlit lagoon of Selene with crates of tunnels, and Aria the bookkeeper must account for every last one. 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 <= 1909; 0 <= m <= 3818.

Example 1:

Input: 1845 2698 1 1845 799 861 1171 1447 206 240 860 1006 288 1289 1340 1633 2 996 341 1037 342 762 77 1649 643 1345 1232 1458 97 1330 1125 1739 599 698 285 1147 239 1672 1472 1533 70 1427 562 604 116 359 514 829 227 278 589 602 620 1138 400 1740 18 1496 432 978 1090 1759 568 721 458 1726 1133 1234 66 1297 1161 1476 254 491 479 1444 1396 1410 660 1397 1414 1755 508 852 510 1076 100 1338 108 1758 937 1571 598 1575 557 1308 489 1507 338 1424 1600 1828 334 514 303 628 307 1144 189 1123 1021 1288 1482 1782 331 1279 994 1161 488 782 1153 1598 48 426 364 1214 193 1743 462 1056 913 1186 711 1349 340 859 1004 1184 1298 1789 71 1072 1371 1646 275 977 944 1468 523 1299 153 631 85 1499 326 1696 78 1375 68 334 559 1554 566 1469 557 703 957 1805 804 1482 929 1222 586 705 505 1782 601 1219 1327 1607 439 1288 …
Output: 10

Example 2:

Input: 540 3792 1 540 58 313 91 98 338 406 186 211 67 528 213 344 40 378 388 472 409 522 189 234 122 287 252 310 166 315 228 340 116 293 366 466 368 376 173 184 83 113 30 493 492 531 54 420 316 337 177 477 85 134 11 339 168 296 110 175 22 489 354 439 28 135 211 467 334 505 274 510 7 191 406 495 280 317 73 285 97 390 221 518 69 498 155 229 85 444 352 447 214 250 101 265 326 455 84 139 235 501 104 164 255 335 216 511 286 308 340 387 122 501 183 518 48 514 97 376 87 294 73 360 181 283 232 522 80 191 205 448 266 308 276 512 138 267 242 338 22 30 162 503 151 517 163 504 358 493 265 364 388 471 215 266 217 472 34 404 11 164 242 368 160 367 90 382 215 508 208 381 328 364 319 335 230 446 193 254 341 420 127 154 11 479 93 125 1 17 30 318 224 472 76 152 286 527 46 209 174 279 117 511 8 255 367 503 112 219 …
Output: 3

Example 3:

Input: 1095 3655 1 1095 566 676 288 811 196 1003 150 955 299 756 615 1018 63 713 353 781 38 127 341 463 72 570 295 542 719 855 17 378 444 760 319 660 17 418 275 724 882 920 716 1015 742 1081 125 326 278 679 129 272 835 863 233 366 549 692 78 473 328 841 314 1017 720 853 249 547 512 902 544 940 521 571 252 336 152 835 651 994 350 513 161 962 308 1027 466 472 346 759 395 657 502 619 556 600 715 1008 186 275 68 579 149 590 383 1016 210 1048 478 858 739 763 638 891 216 940 180 497 86 178 163 918 115 740 64 514 59 177 322 803 452 495 806 863 725 778 262 788 603 745 113 473 364 381 434 735 446 569 294 865 217 746 408 1085 200 521 200 505 79 928 355 583 324 783 772 991 30 873 594 946 260 651 413 743 511 918 57 682 194 295 57 122 101 545 28 1001 955 965 415 879 403 915 117 259 488 662 468 690 497 756 284…
Output: 4

Constraints:

1 <= n <= 1909; 0 <= m <= 3818.

Loading...
Test Cases:No test cases
No test cases available.
Aria's Amber Ledger - MEDIUM Coding Problem | CodeTikki