CT51671

Yusuf's canals Reckoning

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Yusuf runs the brewery at the ivy courts of Vineward. Today the books show a list of canals, and the numbers must be worked out before sundown. 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 <= 1567; 0 <= m <= 3134.

Example 1:

Input: 467 553 1 467 39 289 253 320 285 389 211 392 103 210 96 363 150 355 182 454 319 386 319 412 172 435 90 281 214 462 61 75 79 333 76 132 140 381 130 142 367 466 347 462 185 310 22 284 230 434 121 301 89 402 136 199 202 218 397 449 18 199 34 252 311 338 83 150 254 330 181 279 47 234 134 148 92 230 52 304 21 264 221 240 61 208 215 342 284 304 4 402 104 247 254 261 66 267 124 142 138 379 244 373 99 421 54 162 198 461 334 407 105 401 110 436 419 437 234 382 151 297 77 444 87 251 80 290 224 321 153 333 350 361 134 169 32 325 78 260 300 412 77 139 242 362 60 207 5 436 189 190 141 416 30 410 269 335 2 167 142 171 145 217 325 362 4 437 296 459 300 404 14 460 179 231 159 268 100 280 317 466 196 331 382 417 181 220 61 305 155 281 119 222 33 145 268 327 156 378 137 393 92 284 210 433 234 422 307 329 14…
Output: 3

Example 2:

Input: 940 1318 1 940 7 453 789 815 274 934 84 847 642 693 651 795 53 913 153 316 108 145 253 893 19 470 97 355 11 384 26 921 247 471 796 848 16 896 91 405 145 746 145 656 354 849 212 771 319 491 469 716 187 665 869 919 67 253 761 810 482 819 686 908 394 699 434 769 394 807 491 522 265 669 451 711 196 458 289 484 720 728 326 725 522 897 218 398 514 545 71 239 335 721 395 835 249 717 328 752 485 583 694 904 633 800 68 292 146 382 350 540 265 435 59 652 27 342 437 709 473 931 426 765 377 675 238 650 517 743 85 611 375 699 454 811 182 729 132 345 285 720 568 891 148 859 202 242 162 637 670 842 326 698 258 511 196 698 104 226 532 727 27 889 354 668 21 281 54 61 24 176 764 937 109 623 129 321 499 757 232 820 414 757 622 864 506 755 30 330 857 938 26 926 369 823 99 487 906 927 137 653 367 835 17 718 39…
Output: 5

Example 3:

Input: 454 655 1 454 257 360 35 40 61 438 256 429 230 288 207 231 295 441 31 167 286 346 341 420 208 215 3 59 286 451 403 422 53 172 133 270 202 237 35 257 132 186 85 269 2 260 287 353 113 218 107 356 149 164 303 345 86 399 17 414 216 410 252 402 264 290 43 221 122 230 116 335 323 412 2 160 222 422 186 299 180 216 326 406 323 369 248 292 11 178 169 326 320 345 60 434 79 411 273 339 242 358 199 371 73 190 38 296 122 196 108 331 204 276 330 454 188 350 87 295 193 433 167 366 47 318 166 357 271 287 11 382 64 358 173 286 189 355 245 324 375 442 82 349 145 414 115 334 74 410 177 201 81 323 56 113 254 362 57 297 111 169 124 210 189 196 256 305 173 216 187 304 87 418 111 155 361 387 41 47 105 437 132 425 91 295 336 439 61 210 193 319 20 394 73 204 22 76 127 432 100 131 219 316 71 163 171 309 181 251 76 …
Output: 5

Constraints:

1 <= n <= 1567; 0 <= m <= 3134.

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