The Two Routes
MediumRating 1600CodeforcesShortest Paths & Topological Sort
Approach hintTry it first, then revealHide
Exactly one of the two networks contains the direct edge between towns 1 and n, so that vehicle needs one hour. The answer is the BFS distance in the other network, or -1 if n is unreachable there.