Fortification
Time limit2sMemory limit1024 MB
Given fortification times for locations and roads that flood at set times, find the most locations that can be fortified on a round trip starting and ending at location 1.
- Level
Medium7 of 10
- Topics
- Graph, Shortest path, Greedy
- Solved
- No attempts yet
Statement
A hurricane is approaching. Critical buildings and infrastructure must be fortified by adding extra supplies, installing power generators, or placing sandbags and other flood barriers. Each fortification takes time, and roads flood quickly, so not every plan may be finished in time. Find the maximum number of plans that can be finished under the road flooding constraints.
You are given a list of locations that need fortification, and for each location the time it takes to fortify. A road network connects the locations. For each road, you are given the time it floods. A road can be used up to and including that time, but not later. Driving is instantaneous, since it is fast compared to fortification. Your route must start and end at location 1, the safe depot for the maintenance vehicle.
Input
The first line contains (), the number of data sets. Each data set begins with two integers and (, ), the number of locations to fortify and the number of roads.
The next line contains integers (), the time to fortify location .
Each of the next lines contains three integers , , (, ). Road connects and , can be used in both directions, and floods at time . The same pair of endpoints may appear more than once.
Output
For each data set, print Data Set x: on its own line, where is the data set number. Then print the maximum number of locations that can be fortified under the flooding constraints. Print a blank line after each data set.