Airports
Time limit3sMemory limit256 MB
Find the minimum number of planes needed to operate all scheduled flights when planes can take repositioning flights between them.
- Level
Medium7 of 10
- Topics
- Graph, Shortest path
- Solved
- No attempts yet
Problem
An airline operates flights out of n airports numbered 1 to n. The flight time from airport i to airport j is , and can differ from because of wind and terrain.
When a plane lands at airport i, it must be inspected for before it can take off again. The inspection time depends only on the airport where the plane lands, not on where the plane came from. A plane that lands on an extra repositioning flight is inspected the same way.
The airline must operate all m scheduled flights. Scheduled flight leaves airport at exactly time and flies straight to airport . The airline may add any number of repositioning flights to move planes around, and one plane may make several of them in a row.
A plane that operated scheduled flight can operate scheduled flight next only if it is back at airport with its inspection finished by time . One plane cannot operate two scheduled flights that leave at the same time.
Stated exactly: the plane that finishes flight is ready to take off again at . Let be the smallest time needed to move a plane from airport to airport , which is the minimum, over all routes, of the flight times along the route plus the inspection time at every airport where the plane lands, with . One plane can operate after exactly when and .
Find the minimum number of planes needed to operate all m scheduled flights.
Input
The first line contains two space separated integers and . ()
The second line contains space separated integers . ()
Each of the next lines contains space separated integers. The th integer of the th line is . () It is guaranteed that for every , but and can differ when .
Each of the next lines contains three space separated integers , , and . (, , ) It means the airline must operate a scheduled flight that leaves airport at time and flies straight to airport .
Output
Print, on a single line, the minimum number of planes needed to operate all scheduled flights.