#P4814. King Gruff

    ID: 18058 Type: Default 1000ms 256MiB

King Gruff

King Gruff

This problem is translated from CCO 2014 Day1 T2 "King Gruff".

In a kingdom with NN cities and MM directed roads, each road from city XiX_i to YiY_i has a length LiL_i and a closing fee CiC_i. The despised foxes reside in two different cities AA and BB. To make their journey from AA to BB as troublesome as possible, King Gruff chooses a distance DD and simultaneously closes all roads that lie on some AABB path with total length at most DD. 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 uu to vv will be closed if and only if there exists an AABB path that uses this road and whose total length is at most DD. 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 DD, 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 NN, MM, AA, BB, representing the number of cities, the number of roads, the starting city, and the destination city respectively.

Each of the next MM lines contains four integers XX, YY, LL, CC, indicating there is a directed road from city XX to city YY with length LL and closing fee CC.

The next line contains an integer QQ, the number of queries.

Each of the following QQ lines contains a single integer DD.

outputFormat

For each query, output a single integer — the minimum total cost required to close all roads that are part of an AABB path with total length at most DD.

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>