Dueling GPSs
InterviewTime limit1sMemory limit128 MB
Find a route from intersection 1 to N that minimizes the count of roads lying off either GPS shortest path to the farm.
- Level
Medium6 of 10
- Topics
- Shortest path, Graph
- Solved
- No attempts yet
Problem
Farmer John accidentally ordered two GPS units for his new car. Both use the same map, but each assigns its own travel time to every road.
The map has intersections () and one-way roads (). Road runs from to . Multiple roads may connect the same pair of intersections, and a two-way road appears as two opposite one-way roads. FJ's house is at intersection 1 and his farm at intersection . The farm is reachable from the house.
Road takes time according to the first GPS and time according to the second (each is an integer in ).
When FJ travels from his house to the farm, a GPS complains whenever he uses a road that it does not consider part of any shortest route from the current intersection to the farm. If both GPS units complain on the same road, that adds 2 to the total.
Find the minimum total number of complaints over all routes from 1 to .
Input
- Line 1: and .
- Next lines: , , , .
Output
The minimum total number of complaints.
Hint
Precompute shortest distances to the farm for each GPS, then mark roads that are not on any shortest-path edge as complaints.