CT32268

Wamika's Ledger of canals

MediumL4 · Loop LordAcceptance: 0.0%XP: 35

At the lantern lake of Firefly Mere, Wamika records each canals in a worn leather ledger. The guild wants answers, not guesses. 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 <= 1685; 0 <= m <= 3370.

Example 1:

Input: 758 1015 1 758 412 477 220 475 98 635 207 449 363 610 31 55 21 585 24 39 110 309 573 663 162 716 129 617 463 747 370 557 496 690 233 444 106 262 383 652 13 215 388 592 351 537 446 726 89 645 71 396 56 728 529 575 144 465 189 277 85 185 271 341 188 290 231 294 18 436 102 129 405 607 154 358 93 497 231 480 172 621 333 658 127 629 31 370 119 235 360 652 212 432 379 470 53 482 13 649 229 367 126 591 169 509 576 652 625 736 84 272 460 708 355 660 536 658 480 688 18 94 8 496 404 527 314 380 172 220 53 280 258 673 2 294 112 320 125 558 7 167 212 405 272 404 19 411 399 633 205 682 201 539 563 645 15 141 218 305 22 425 149 156 4 346 63 438 51 526 435 528 475 493 204 347 53 104 150 505 269 297 260 644 227 662 68 288 110 499 183 488 512 598 321 558 144 478 23 152 110 480 59 719 35 140 7 260 93 748 82…
Output: 7

Example 2:

Input: 1162 1161 1 1162 99 1077 483 556 1026 1057 215 567 565 701 271 539 81 280 179 493 27 373 2 514 132 577 481 643 36 39 243 312 315 915 16 194 782 994 378 461 206 632 296 842 102 164 581 609 353 784 997 1056 161 720 122 905 484 657 354 365 346 960 797 1069 225 1061 323 715 215 221 366 581 309 357 353 574 779 1157 281 1156 419 999 218 497 254 1078 194 665 150 795 408 977 42 888 31 569 57 433 245 1136 236 394 263 718 794 941 641 1087 594 891 460 696 124 564 568 1118 495 1109 254 1098 205 915 540 601 221 466 942 1055 684 698 3 1092 88 1127 372 734 343 475 258 365 71 253 438 1035 492 883 387 538 144 1061 111 407 420 865 336 1002 42 231 627 1125 67 607 350 454 266 865 652 1093 204 526 190 281 297 645 507 721 106 390 669 841 936 971 15 880 247 932 43 618 728 825 143 462 372 896 440 710 92 753 293 1…
Output: 16

Example 3:

Input: 485 916 1 485 346 386 213 396 113 234 77 377 97 223 67 381 301 338 42 396 326 405 100 204 105 374 36 266 59 131 59 174 72 202 273 282 38 61 142 376 291 331 127 354 119 308 204 354 11 246 67 336 63 226 99 178 45 132 30 91 286 337 26 369 277 281 66 227 165 231 14 283 20 316 243 402 297 472 416 457 131 282 97 161 175 228 104 195 168 353 67 79 133 281 115 344 5 122 404 441 240 366 85 167 225 296 62 172 277 476 83 441 143 210 146 212 94 356 15 148 118 202 129 477 9 454 162 194 241 395 62 256 19 375 52 437 195 378 90 167 267 420 211 414 370 466 5 249 75 428 48 173 17 25 70 322 43 353 368 410 140 342 130 478 374 448 301 445 268 467 108 110 341 405 341 344 214 372 233 431 357 468 122 317 157 395 421 442 130 301 39 253 123 459 75 124 255 270 78 229 126 348 293 381 116 374 220 410 170 413 16 296 372…
Output: 6

Constraints:

1 <= n <= 1685; 0 <= m <= 3370.

Loading...
Test Cases:No test cases
No test cases available.
Wamika's Ledger of canals - MEDIUM Coding Problem | CodeTikki