CT34004

Varun's Wayward routes

MediumL4 · Loop LordAcceptance: 0.0%XP: 35

The inventory keeper Varun has been asked to verify the ledger before the auditors arrive. On the desk lies a long table of routes readings. 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 <= 902; 0 <= m <= 1804.

Example 1:

Input: 373 1185 1 373 32 91 170 361 166 314 114 328 65 333 8 345 77 182 168 324 236 318 21 112 9 136 46 259 109 173 19 310 24 299 82 109 135 333 70 80 16 224 161 220 293 309 165 318 124 222 3 7 160 300 33 316 308 347 13 313 32 266 63 81 107 340 21 30 151 323 139 210 169 212 33 80 194 368 353 369 41 345 141 247 180 308 181 228 68 105 270 340 95 204 323 358 71 236 310 330 57 180 260 323 252 266 233 261 2 244 276 351 233 280 123 309 136 193 254 336 170 175 242 334 4 199 8 86 271 272 14 56 4 294 36 149 355 361 220 236 286 370 192 202 257 365 94 170 52 333 139 140 81 224 18 115 305 364 114 325 148 343 24 252 130 212 93 233 85 368 73 321 121 200 206 331 46 80 200 295 18 128 65 76 72 345 28 162 24 60 45 294 38 134 212 362 82 147 6 112 64 259 290 330 90 136 271 367 187 327 252 349 281 329 5 183 140 162 1…
Output: 4

Example 2:

Input: 369 368 1 369 68 291 3 315 275 321 78 344 115 125 197 225 25 310 107 357 206 299 245 346 153 231 7 220 88 167 102 321 19 198 193 365 211 279 66 271 9 214 98 105 161 216 104 193 84 339 40 72 19 323 181 202 138 180 85 194 54 163 25 181 138 234 263 268 46 366 23 303 162 261 46 187 184 253 124 179 107 235 248 340 117 221 104 349 37 204 27 266 177 190 179 321 54 119 129 351 5 110 273 364 244 281 120 169 4 81 136 368 21 163 102 143 205 283 135 222 128 144 160 327 351 354 112 171 62 261 15 225 54 240 102 333 87 198 36 76 43 184 70 293 1 42 190 358 54 154 90 186 159 178 8 196 177 320 8 282 40 174 33 63 56 214 106 343 133 272 64 199 57 345 14 312 82 148 34 293 156 280 275 340 60 119 102 190 192 233 91 139 203 217 52 306 161 179 108 139 195 313 77 150 69 254 120 130 128 335 247 324 116 136 251 322 3…
Output: 12

Example 3:

Input: 593 1658 1 593 334 533 270 283 50 556 20 275 131 570 84 353 30 132 248 397 232 255 235 587 92 162 271 566 124 457 164 522 399 449 262 357 351 457 193 581 159 389 301 472 359 547 146 504 218 386 191 297 104 143 143 166 38 552 456 462 170 273 239 589 226 372 133 433 104 304 126 281 251 391 106 445 452 575 102 416 233 286 198 585 23 87 248 420 4 405 400 423 155 431 199 281 131 137 35 105 131 178 29 350 289 386 57 212 348 528 171 578 78 580 296 349 149 452 7 520 42 542 132 224 22 579 38 581 106 583 479 521 224 383 27 444 8 123 97 251 6 246 145 338 304 367 101 549 290 411 359 491 480 568 65 534 224 286 341 468 402 570 58 339 28 198 326 495 43 142 301 537 320 521 138 421 453 585 93 219 445 560 123 575 191 420 344 350 453 544 369 384 119 125 375 416 270 559 297 425 372 530 300 348 216 356 307 534…
Output: 4

Constraints:

1 <= n <= 902; 0 <= m <= 1804.

Loading...
Test Cases:No test cases
No test cases available.
Varun's Wayward routes - MEDIUM Coding Problem | CodeTikki