#P4814. King Gruff
King Gruff
King Gruff
This problem is translated from CCO 2014 Day1 T2 "King Gruff".
In a kingdom with cities and directed roads, each road from city to has a length and a closing fee . The despised foxes reside in two different cities and . To make their journey from to as troublesome as possible, King Gruff chooses a distance and simultaneously closes all roads that lie on some – path with total length at most . A path is defined as a sequence of roads (possibly revisiting cities or reusing roads) where, except for the first road, every road starts at the endpoint of the previous road.
The key observation is that a road from to will be closed if and only if there exists an – path that uses this road and whose total length is at most . This can be checked by verifying whether
[
\text{dist}(A,u) + L_{(u\to v)} + \text{dist}(v,B) \le D,
]
where (\text{dist}(X,Y)) denotes the shortest distance from city (X) to city (Y).
Your task is to, given several queries with different values of , compute the minimum total cost the king must incur, i.e. the sum of closure fees of all roads that satisfy the above condition.
inputFormat
The first line contains four integers , , , , representing the number of cities, the number of roads, the starting city, and the destination city respectively.
Each of the next lines contains four integers , , , , indicating there is a directed road from city to city with length and closing fee .
The next line contains an integer , the number of queries.
Each of the following lines contains a single integer .
outputFormat
For each query, output a single integer — the minimum total cost required to close all roads that are part of an – path with total length at most .
sample
4 4 1 4
1 2 1 2
2 4 1 3
1 3 2 1
3 4 2 5
3
3
4
5
5
11
11
</p>