Zombie Apocalypse
Time limit5sMemory limit512 MB
Move up to g people from the start across directed roads with entry limits and travel times to get the most to a hospital by time s.
- Level
Medium7 of 10
- Topics
- Graph, Simulation
- Solved
- No attempts yet
Problem
The year is 2020. You and your group are trapped in a town inside a city that zombies have wrecked. Your group is already infected, so you have to reach a hospital and get treated before you turn. Everyone in the group is a scientist, so sneaking past the zombies is safer than charging at them to force a way through. Zombies are everywhere, and on some roads sneaking through takes longer than on others. Splitting into several groups that move on their own is sometimes far safer than travelling together.
The infection did not go far enough to give these zombies eyes in the back of their heads. On some roads one direction is easy to sneak along while going back the other way is hard or impossible.
Find the largest number of people in your group who can avoid the zombies and reach a hospital before they turn.
Input
The first line holds the number of test cases. Each test case has the form below. Every value is an integer.
- The first line holds the number of places . ()
- The next line holds the place where the group starts, the number of people in the group, and the time it takes to turn into a zombie. (, , )
- Someone who reaches a hospital at time has found it before turning.
- The next line holds the number of hospitals . ()
- Each of the next lines holds the number of a place that has a hospital. ()
- The next line holds the number of roads . ()
- Each of the next lines holds the road values , , , . (, , , ) The road runs from to , at most people step onto it at each unit of time, and crossing it takes units of time.
The group is at place at time . People step onto a road at integer times, and someone who steps onto a road at time arrives at the far place at time .
Between any pair of places there are at most 2 roads, one per direction. Every place is safe enough to stand and wait in for as long as you like, and there is no limit on how many people a place holds.
Output
For each test case, print on its own line the largest number of people who reach a hospital without being infected.