Charged Courier
A courier must travel through a network of cities from city 1 to city N. Each road can only be used in its listed direction, gives a certain delivery reward, and consumes some amount of battery.
The courier starts with at most B battery units and cannot spend more than B battery units over
the whole trip. Determine the maximum total reward the courier can collect while reaching city N.
If it is impossible to reach city N, output -1.
Input
The first line contains three integers N, M, and B: the number of cities, the number of roads, and the maximum battery that may be spent.
Each of the next M lines contains four integers ui, vi, ri, and ci, describing a directed road from city ui to city vi with reward ri and battery cost ci.
Output
Output one integer: the maximum reward possible while reaching city N using at most B battery
units, or -1 if city N cannot be reached.
Constraints
- 2≤N≤500
- 0≤M≤5000
- 0≤B≤3000
- 1≤ui,vi≤N
- ui=vi
- 0≤ri≤109
- 1≤ci≤3020
Example 1
4 5 7
1 2 10 3
2 4 20 4
1 3 25 5
3 4 10 3
2 3 15 2
30
Explanation
The courier can travel from city 1 to city 2 to city 4, spending 3+4=7 battery and collecting 10+20=30 reward. The route through city 3 from city 1 would collect more reward, but it spends too much battery.
Example 2
3 2 4
1 2 100 5
2 3 100 1
-1
Comments0
No comments yet
Be the first to comment.
New comment
Log in to join the discussion.