




Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
It can be proven that it is optimal to go only to the positions that are either the start or the end of a special road or the target position.
Consider all positions given to you as nodes in a graph, and the edges of the graph are the special roads.
Now the problem is equivalent to finding the shortest path in a directed graph.