Fewest Hops
A network of routers is connected by cables (undirected). What is the minimum number of cables a packet must cross to go from router to router ? Print -1 if it can't reach.
Input
and , lines u v, then s t.
Output
The minimum number of hops, or -1.
Constraints
,
Sample 1
Input
5 5 1 2 2 3 3 4 1 5 5 4 1 4
Output
2
Sample 2
Input
3 1 1 2 1 3
Output
-1