시간 제한 | 메모리 제한 | 제출 | 정답 | 맞은 사람 | 정답 비율 |
---|---|---|---|---|---|

5 초 | 256 MB | 22 | 11 | 8 | 53.333% |

You and the rest of your team are stuck in a town during the zombie apocalypse of 2020. You all might be infected with the virus and hence you will have to find your way to one of the medical facilities to get a cure before you also become zombies. Because you are scientists you quickly realize that it is safer to try and sneak your way past the zombies than to recklessly start fighting them. Obviously the zombies are everywhere so some streets might take more time to sneak through than others. It is also obvious that by splitting up into smaller groups it is easier to move around undetected.

Furthermore, since these zombies have not mutated to the extent that they actually have eyes in the back of their heads, it might be easy to cross some streets in one direction while hard or impossible to cross them in the other direction.

How many of you can sneak past all the zombies and get to a medical facility in time?

On the first line one positive number: the number of test cases, at most 100. After that per test case:

- one line with a single integer n (1 ≤ n ≤ 1 000): the number of locations in the town.
- one line with three space-separated integers i, g and s (1 ≤ i ≤ n and 1 ≤ g ≤ 100 and 1 ≤ s ≤ 100): the starting location of your group, the number of people in it, and the number of time steps you have to get to the safety of a medical facility, respectively.
- one line with a single integer m (1 ≤ m ≤ n): the number of medical facilities in the town.
- m lines, each with a single integer x (1 ≤ x ≤ n): the location of each of the medical facilities.
- one line with a single integer r (0 ≤ r ≤ 1 000): the number of roads in the town.
- r lines, each with four space-separated integers a, b, p and t (1 ≤ a, b ≤ n and a ≠ b and 1 ≤ p ≤ 100 and 1 ≤ t ≤ 100), indicating that there is a road from a to b, which p people can enter at every time step and takes t timesteps to traverse.

There are at most two roads – one in each direction – between any pair of locations. The locations are safe enough to wait at for any amount of time and do not have a limit on the number of people that can be there.

Per test case:

one line with a single integer: the largest number of people that can get to a medical facility in time.

2 4 3 8 5 2 2 4 5 1 2 1 3 3 2 1 4 3 1 2 1 1 4 1 3 3 4 1 3 4 3 10 5 2 2 4 5 1 2 1 3 3 2 1 4 3 1 2 1 1 4 1 3 3 4 1 3

8 9