CT36852

Last corridors of Kavi

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Kavi the factor watches over the frontier camp of Duskwood's stores of corridors. A careful computation stands between order and chaos. 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 <= 2769; 0 <= m <= 5538.

Example 1:

Input: 642 2296 1 642 1 193 278 637 272 351 355 446 71 508 95 604 367 417 50 632 442 484 90 249 170 174 266 520 211 274 86 371 128 273 234 238 16 462 63 199 74 189 35 145 38 180 32 525 332 338 378 382 95 203 39 437 89 460 358 378 599 609 121 143 127 404 252 313 294 313 108 398 124 379 354 628 59 406 352 481 134 507 374 399 234 482 460 556 74 268 139 206 1 35 99 433 197 250 276 297 204 260 265 475 178 511 178 494 191 476 131 335 212 409 182 201 61 101 37 550 169 588 459 545 439 573 128 160 333 599 268 599 78 629 238 340 5 405 306 358 438 578 101 498 427 578 100 202 164 337 45 66 386 632 22 355 155 453 371 451 58 337 58 266 257 406 451 598 440 491 181 203 144 502 382 489 326 365 265 365 121 288 21 615 124 481 65 327 72 317 44 224 107 444 197 269 277 550 104 591 127 260 229 500 405 492 213 540 390 5…
Output: 3

Example 2:

Input: 1787 3344 1 1787 526 699 334 895 1624 1751 90 253 323 615 631 1332 44 1253 1085 1660 758 1740 62 174 82 1403 603 654 136 1739 1410 1535 182 1733 269 609 352 1683 151 415 1155 1319 183 658 1568 1644 162 956 599 1685 1010 1647 428 583 418 1236 375 470 854 1090 20 1618 899 1552 242 1243 290 1779 56 1502 842 1136 1230 1233 704 1770 644 1599 460 1174 208 554 456 1406 202 1391 703 1384 50 1700 23 1627 1143 1173 689 1725 49 1234 657 1058 360 848 98 1446 907 1712 163 1604 449 746 633 1536 396 589 294 1672 757 1097 500 1020 1408 1507 861 890 1083 1585 1175 1619 8 576 63 607 1194 1276 114 1352 17 1312 870 1250 1428 1558 110 670 751 1503 283 675 423 944 1535 1613 705 1124 15 691 1171 1732 627 1723 1393 1471 551 1619 1170 1770 1660 1713 1341 1474 159 1135 439 1339 789 1297 742 753 785 797 1257 1555 81…
Output: 6

Example 3:

Input: 826 910 1 826 242 360 151 414 249 495 275 645 80 595 638 689 269 681 23 317 558 601 214 634 386 653 684 744 575 694 236 381 391 439 126 474 400 418 554 722 86 526 46 206 452 676 125 342 431 591 596 744 358 499 467 535 438 465 254 287 480 582 363 576 325 814 574 696 363 756 39 340 405 551 77 715 63 71 10 696 630 652 49 729 216 608 413 723 563 785 255 676 55 188 799 810 50 374 592 685 430 771 599 788 126 215 38 146 247 287 40 558 174 526 332 624 491 765 161 184 11 548 71 716 442 483 91 501 242 576 131 208 716 724 379 635 256 295 73 748 432 736 124 820 188 577 196 221 291 463 262 725 257 305 392 700 216 340 152 503 359 773 104 536 58 719 310 498 281 410 286 359 195 555 175 421 352 810 625 649 186 346 464 720 362 727 761 812 252 410 561 698 244 550 116 723 281 364 357 666 134 159 164 694 398 6…
Output: 11

Constraints:

1 <= n <= 2769; 0 <= m <= 5538.

Loading...
Test Cases:No test cases
No test cases available.
Last corridors of Kavi - MEDIUM Coding Problem | CodeTikki