CT29851

Wynne's bridges Reckoning

MediumL4 · Loop LordAcceptance: 0.0%XP: 35

Deep in the wheat plains of Amberfield, Wynne studies rows of bridges entries. One clean number will settle the guild's oldest argument. 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 <= 1331; 0 <= m <= 2662.

Example 1:

Input: 1239 1238 1 1239 236 1235 293 1161 316 495 556 558 801 1219 329 1031 256 825 282 1104 1192 1226 240 1154 77 983 27 133 640 991 15 253 759 1212 695 1000 211 383 367 876 104 610 313 315 474 950 839 931 172 956 348 1058 596 832 309 741 263 1109 317 344 360 1182 202 1116 410 1053 332 424 373 564 63 337 112 386 499 1111 100 728 151 925 466 530 229 1078 427 586 185 902 732 901 406 735 314 773 565 792 279 487 296 786 462 1206 939 1170 8 526 361 630 580 621 586 763 91 711 114 709 1099 1136 614 1164 699 949 3 1023 190 1206 80 1141 757 1235 5 1027 560 911 545 762 448 463 131 989 449 1045 460 1117 93 257 660 1238 883 903 41 474 274 705 444 732 758 1168 65 172 292 1105 122 1237 332 1137 85 714 1165 1209 328 454 68 746 775 1081 823 836 409 942 848 884 59 1101 84 781 58 1196 366 957 838 1230 353 649 751…
Output: 15

Example 2:

Input: 255 279 1 255 88 242 121 220 134 143 60 214 25 204 173 228 135 181 141 210 23 142 51 192 95 182 8 40 71 209 2 145 21 188 51 211 58 215 140 194 35 152 123 135 189 223 203 253 107 150 73 173 4 139 103 196 9 20 47 99 205 255 158 187 23 61 107 165 3 86 18 128 104 233 82 141 38 108 160 182 182 188 165 227 116 126 40 73 74 78 194 239 76 113 99 235 188 242 62 154 216 245 130 230 52 251 49 248 115 189 23 245 138 184 131 168 73 241 165 230 155 197 129 251 193 244 114 157 44 248 66 250 33 149 160 169 50 151 175 225 80 221 182 206 13 139 126 186 26 229 76 249 51 179 91 168 92 223 3 246 98 149 123 148 1 10 7 236 56 199 54 69 81 122 3 109 132 253 3 73 201 215 110 138 47 188 173 174 135 241 47 124 20 193 109 240 111 130 7 26 24 88 114 162 200 253 139 248 125 238 51 79 234 255 73 93 9 215 11 92 56 107 54…
Output: 7

Example 3:

Input: 515 1172 1 515 185 439 175 354 304 390 121 410 277 466 230 322 245 393 39 89 100 123 65 290 161 398 104 340 22 191 82 345 85 309 160 465 183 379 3 14 235 515 322 358 352 489 156 459 151 190 310 318 387 465 52 410 432 441 196 294 57 62 426 505 401 451 60 315 338 451 114 279 72 177 76 440 358 393 47 147 93 227 214 352 370 441 83 232 264 361 263 309 17 490 338 364 45 389 336 510 178 216 42 503 58 425 279 334 64 378 35 274 327 410 219 338 270 395 10 150 63 143 224 454 278 335 2 455 43 436 286 358 77 189 357 464 317 450 117 463 171 250 148 403 274 412 254 499 263 467 190 490 54 360 73 305 249 427 64 224 76 88 213 493 355 398 100 447 187 417 231 269 153 460 385 473 19 52 71 498 185 506 200 248 8 138 141 230 77 493 341 358 196 374 2 20 210 304 133 186 176 212 208 393 131 297 453 474 96 492 18 271…
Output: 3

Constraints:

1 <= n <= 1331; 0 <= m <= 2662.

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