Shelter
Time limit4sMemory limit1024 MB
Find the minimum time for every resident to reach a shelter along shortest paths, with each shelter holding at most its capacity.
- Level
Medium7 of 10
- Topics
- Binary search, Shortest path, Bit manipulation
- Solved
- No attempts yet
Problem
In a dimly lit room, at about 23:55, Milan sits at a three-legged table and thinks about the possible consequences a nuclear disaster would have on his city. As mayor, he knows all the relevant facts well.
The city has exactly residents, and each resident lives in a house of their own. Exactly pairs of houses are connected by roads, and the time needed to travel each road is known. Exactly houses contain atomic shelters, and the capacity of each shelter is known. Milan keeps asking himself: "What is the minimum time needed to evacuate all residents of this city?"
Evacuation means that every resident ends up in some atomic shelter. Residents move optimally (along shortest paths), and several people may move along the same road at the same time in different directions. You may also assume that any two houses are connected by a path that uses some subset of the given roads.
Input
The first line contains natural numbers (), (), and (), which are the number of residents, the number of roads, and the number of shelters. Houses are numbered from 1 to .
Each of the next lines contains three natural numbers , (, ), and (). This means there is a road between houses and , and passing through it takes units of time.
Each of the next lines contains two natural numbers () and (). This means house has an atomic shelter that can hold at most people. The total capacity of all shelters is at least .
Output
Print one line with the minimum time needed to evacuate all residents of the city.
Hint
In the first sample, within 3 units of time, the people from houses 1, 2, and 3 can reach the shelter in house 1, and the people from houses 4 and 5 can reach the shelter in house 4. A shorter time is not enough for everyone to reach a shelter, because the shelter in house 4 holds at most two people.