CT31399

Cora's Zigzag Ledger

MediumL4 · Loop LordAcceptance: 0.0%XP: 35

Caravans arrive at the bamboo terraces of Verdantstep with crates of tunnels, and Cora the assayer 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 <= 1255; 0 <= m <= 2510.

Example 1:

Input: 633 1672 1 633 402 429 189 383 523 533 111 294 443 445 333 632 308 537 104 186 127 552 292 502 289 558 274 384 100 310 138 248 50 602 42 481 612 619 371 461 347 489 235 423 284 565 30 333 149 187 74 244 364 416 33 284 132 511 366 402 266 582 33 568 204 274 316 471 463 606 86 427 236 604 458 499 374 573 308 479 123 360 238 310 274 444 56 335 77 259 349 551 161 269 440 557 404 604 133 626 142 487 5 257 127 575 213 617 542 574 203 394 87 202 453 538 179 299 104 129 128 615 383 416 236 522 35 325 208 291 418 492 8 84 385 569 436 452 314 557 222 344 546 586 347 452 240 367 126 477 9 213 86 445 293 582 77 624 259 308 107 201 151 373 453 475 250 403 41 246 372 474 255 290 333 427 105 329 133 544 23 468 191 411 56 194 150 386 255 345 234 269 572 619 59 324 292 313 265 341 449 550 50 569 420 465 12…
Output: 3

Example 2:

Input: 924 923 1 924 433 607 12 462 221 276 12 42 732 886 237 826 253 556 582 772 517 841 190 426 79 387 290 701 23 331 321 512 165 415 705 881 301 535 10 750 183 402 402 901 93 798 502 544 38 584 538 566 103 677 661 897 427 814 28 30 231 448 43 665 816 891 373 446 608 672 193 706 527 829 431 731 524 747 21 186 101 662 156 682 467 697 571 628 415 908 541 817 130 557 90 382 701 706 444 718 212 798 444 833 217 586 514 583 713 881 32 45 41 707 679 747 444 530 385 878 758 831 395 922 120 338 28 215 269 446 66 744 339 744 827 877 491 840 368 602 176 495 332 476 445 764 616 781 328 692 657 801 606 683 382 776 215 781 182 405 445 910 156 763 125 872 522 593 670 701 282 721 305 855 711 909 17 115 148 664 840 883 127 455 211 787 88 389 25 877 19 500 207 667 64 116 414 729 500 517 154 458 229 269 8 788 225…
Output: 12

Example 3:

Input: 1055 1523 1 1055 83 646 542 1029 202 445 293 588 296 873 202 359 390 608 58 884 686 860 148 728 546 586 148 175 3 713 546 819 517 595 88 932 431 669 556 751 278 282 374 717 105 189 607 635 761 1036 820 943 401 447 139 686 775 845 646 993 667 912 161 694 851 1041 419 914 272 934 123 383 129 663 491 769 366 1052 355 423 264 994 169 507 728 1039 133 306 555 849 753 768 100 691 61 584 374 869 35 455 340 445 331 596 232 668 521 967 11 835 776 848 352 1005 182 553 366 547 270 354 118 347 785 899 172 638 228 476 327 473 334 929 308 444 457 612 397 1012 210 354 130 257 401 633 596 690 928 1040 159 586 610 696 128 729 369 555 604 1019 51 457 479 927 891 1005 69 906 761 890 385 866 363 864 261 298 460 480 309 424 684 1028 244 272 69 781 7 483 377 1027 100 107 350 746 117 287 756 1009 75 908 213 1024…
Output: 7

Constraints:

1 <= n <= 1255; 0 <= m <= 2510.

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