#P3720. [AHOI2017初中组] guide
[AHOI2017初中组] guide
Description
Farmer John recently bought a new car online. While ordering accessories, he accidentally clicked the “Submit” button twice, so the car was fitted with two GPS systems. Even worse, the two systems often suggest different routes during navigation. The region where John lives has () intersections and () directed roads. The -th road goes from intersection () to (). There may be multiple roads between the same pair of intersections. A bidirectional road can be modeled as two directed roads in opposite directions.
John’s home is at intersection , and the farm is at intersection . John can drive from home to the farm along a sequence of directed roads. Both GPS systems share the same base map; the only difference is how they compute travel times for each road. For the -th road, the first GPS estimates a travel time of units, and the second GPS estimates units. All road travel times are integers in the range to .
John wants to drive from home to the farm. Along the way, the GPS systems keep nagging him with prompts like “Please go from intersection to intersection .” This happens because John follows the route recommended by one GPS, while the other GPS considers this not to be a shortest path from to the farm. We call each such event a complaint from a GPS.
Please compute the minimum total number of complaints John will hear if he chooses an appropriate route to the farm. If, on some road, both GPS systems complain, then the total number of complaints increases by .
Input Format
The first line contains two integers and .
The next lines describe the roads. The -th line contains .
Output Format
Output a single integer, the minimum total number of complaints along John’s route.
5 7
3 4 7 1
1 3 2 20
1 4 17 18
4 5 25 3
1 2 10 1
3 5 4 14
2 4 6 5
1
Hint
Translated by ChatGPT 5
京公网安备 11011102002149号