In Case of an Invasion, Please. . .
Time limit3.5sMemory limit512 MB
Place people from n city nodes, with at most 10 capacity-limited shelters on a weighted road network, to minimize the latest arrival time at any shelter.
- Level
Hard9 of 10
- Topics
- Binary search, BFS, Graph, Greedy
- Solved
- No attempts yet
Problem
After Curiosity discovered not just water on Mars, but also an aggressive, bloodthirsty bunch of aliens, the Louvain-la-Neuve municipal government decided to take precautionary measures; they built shelters in order to shelter everyone in the city in the event of an extraterrestrial attack.
Several alien-proof shelters have been erected throughout the city, where citizens can weather an alien invasion. However, due to municipal regulations and local building codes the shelters are limited in size. This makes it necessary for the government to assign every citizen a shelter to calmly direct themselves towards in the rare event of a fleet of UFOs blotting out the sun. On the condition that no shelter is assigned more people than it can fit, it is of the utmost importance that the time it takes until everyone has arrived at a shelter is minimized.
We model Louvain-la-Neuve as a network of n locations at which people live, connected by m bidirectional roads. Located at s points throughout the city are the shelters, each with a given maximum capacity. What is the minimum amount of time it takes for everyone to arrive at a shelter, when we assign people to shelters optimally?
The Louvain-la-Neuve municipal government has made sure that there is enough shelter capacity for its citizens and that all shelters can be reached from any location, i.e. it is always possible to shelter everyone in some way.
Input
- On the first line are three integers, the number of locations , roads , and shelters .
- Then follows a line with n integers , indicating the number of people living at location .
- Then follow m lines containing three integers and indicating that there is a bidirectional road connecting u and v that takes w time to traverse. For any two locations there is at most one road connecting them directly, and no road connects a location to itself.
- Finally follow s lines with two integers and , indicating that there is a shelter with capacity at location .
Output
Print the minimum amount of time it takes to shelter everyone.