Loading...
Loading...
Loading...
Offices are joined by two-way links. Print the smallest number of links on any route from office s to office t, or -1 if no route exists.
Example 1
Input
6 6 0 1 1 2 2 5 0 3 3 4 4 5 0 5
Output
3
Both routes use three links.
Example 2
Input
4 2 0 1 2 3 0 3
Output
-1
Try the problem first. Open one hint at a time.
Every link counts the same, so use BFS.
Store a distance for each node when you first reach it.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor