CT55524

Zane's Ruby canals

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Caravans arrive at the sulphur springs of Brimstone with crates of canals, and Zane the paymaster 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 <= 1987; 0 <= m <= 3974.

Example 1:

Input: 1204 2829 1 1204 686 726 762 934 482 1080 816 879 199 306 426 834 188 1126 744 853 690 1115 53 138 138 208 41 573 57 365 324 581 632 1114 515 1170 51 1098 385 813 934 1114 688 742 64 680 899 1015 29 1121 175 265 83 281 598 756 303 644 22 52 779 805 509 959 51 442 642 1078 92 753 696 979 104 1169 283 714 110 913 26 334 661 1111 1046 1190 146 302 911 1093 625 960 338 849 726 925 672 1061 390 843 629 820 85 644 255 311 284 809 318 683 121 418 510 571 570 939 31 591 584 737 350 588 633 1174 785 1064 641 1078 201 372 23 1163 107 346 317 751 771 852 762 1052 59 350 336 773 529 560 134 436 661 971 817 983 120 169 591 1128 84 456 217 238 389 1029 38 271 478 1056 152 650 556 1150 352 627 418 679 74 835 116 702 577 979 26 89 225 1079 7 377 327 654 670 1044 690 791 12 615 709 856 425 875 427 1154 392…
Output: 5

Example 2:

Input: 576 3765 1 576 394 396 270 514 457 467 206 371 297 485 230 529 21 344 327 446 29 375 19 523 394 417 307 494 379 446 122 370 58 538 184 219 508 520 431 455 178 326 146 557 400 458 312 404 32 572 10 111 22 465 283 421 135 188 173 313 418 516 467 510 64 384 85 206 223 529 192 298 339 523 175 524 312 420 404 549 195 447 42 420 5 420 190 294 312 315 367 522 304 520 22 63 192 338 133 489 523 550 321 522 42 506 136 358 216 522 107 292 458 498 419 504 242 390 433 474 105 160 427 558 49 96 264 353 94 363 143 214 182 456 18 46 398 546 69 417 30 251 224 501 338 434 301 566 67 182 461 465 115 400 207 398 88 184 47 461 49 60 149 337 132 159 487 519 180 260 44 156 465 556 136 483 178 496 62 422 22 74 59 433 320 414 151 525 368 527 158 484 443 495 373 505 372 467 76 356 303 455 308 457 61 520 248 370 316…
Output: 3

Example 3:

Input: 8 8 1 8 1 3 1 8 3 7 6 8 2 6 7 8 3 5 4 7
Output: 1

Constraints:

1 <= n <= 1987; 0 <= m <= 3974.

Loading...
Test Cases:No test cases
No test cases available.
Zane's Ruby canals - MEDIUM Coding Problem | CodeTikki