CT29627

Wade's Fewest Hops Ledger

MediumL4 · Loop LordAcceptance: 0.0%XP: 35

Caravans arrive at the savanna camp of Amberplain with crates of roads, and Wade the tallyman 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 <= 709; 0 <= m <= 1418.

Example 1:

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

Example 2:

Input: 85 1160 1 85 17 28 31 40 9 32 61 75 3 56 51 78 12 30 23 48 3 69 15 52 33 84 18 38 51 72 7 22 79 83 18 55 33 44 68 76 49 66 3 84 11 47 35 36 8 65 31 74 36 48 10 59 1 76 30 40 7 45 22 79 36 72 45 83 72 76 8 21 63 79 9 30 39 56 18 45 7 34 40 55 26 80 25 31 19 42 32 42 28 44 25 79 39 53 41 43 3 19 3 17 51 68 6 42 15 34 65 73 11 35 47 73 22 54 36 66 2 80 39 64 2 69 32 33 42 50 32 57 3 57 18 21 8 20 10 56 24 80 7 29 2 22 13 58 3 61 5 49 43 49 2 27 20 34 1 78 18 19 8 31 25 57 9 20 24 53 24 33 13 26 12 28 1 60 16 27 25 60 13 68 35 50 31 63 11 56 10 21 6 30 23 75 51 59 39 58 24 71 7 52 62 64 18 39 24 60 4 22 6 18 24 75 56 71 26 38 17 69 7 77 21 76 2 70 46 48 24 59 31 71 17 29 36 83 9 41 54 62 2 58 83 85 1 71 2 48 9 58 26 79 64 77 20 45 13 21 5 23 17 61 45 72 60 84 22 48 20 59 2 39 17 58 42 71 34 57…
Output: 2

Example 3:

Input: 65 400 1 65 53 59 7 11 43 60 33 42 22 29 31 37 61 64 23 25 47 50 29 32 41 51 23 49 1 37 43 65 32 38 19 61 2 6 4 55 14 31 43 59 9 45 18 55 24 31 42 62 13 36 11 60 31 49 34 40 6 40 35 45 30 42 36 65 41 47 6 46 5 59 1 36 39 41 9 48 9 37 38 51 46 53 56 61 8 11 22 63 12 39 30 50 8 13 2 52 43 56 8 32 12 34 43 52 18 32 44 59 44 60 21 49 44 62 14 27 23 63 14 21 21 53 8 58 34 61 21 65 54 57 31 42 35 40 26 38 19 59 40 44 20 26 47 54 36 54 2 10 33 45 29 64 32 52 20 24 26 36 10 37 14 39 34 59 28 62 4 23 46 50 34 64 26 47 32 65 21 48 35 49 60 63 29 43 5 50 57 65 47 60 47 49 18 64 36 42 2 11 23 62 15 45 44 64 13 26 1 45 30 52 46 58 6 18 15 58 44 56 25 39 51 65 18 21 24 51 19 45 6 43 19 55 19 57 20 62 20 22 12 15 28 64 12 50 4 40 31 40 10 15 28 57 45 57 7 21 21 60 23 35 6 55 17 20 31 35 28 58 51 59 47 53…
Output: 2

Constraints:

1 <= n <= 709; 0 <= m <= 1418.

Loading...
Test Cases:No test cases
No test cases available.
Wade's Fewest Hops Ledger - MEDIUM Coding Problem | CodeTikki