Trucking Troubles
Time limit1sMemory limit128 MB
Find the maximum weight W such that keeping only bridges with capacity at least W still lets city 1 reach every destination city.
- Level
Medium6 of 10
- Topics
- Union-find, Graph, Sorting, Greedy
- Solved
- No attempts yet
Problem
You sell trucks that can carry trucks that can carry trucks, so your trucks are extremely heavy. To deliver one, you must drive it across a wide, wet region, and because it is wet you have to cross bridges along the way.
The region has cities, numbered from to . Between some pairs of cities there is a road, and every road carries a bridge — but not every pair of cities is connected by a direct road. Each bridge has a maximum weight capacity, an integer from to ; a truck may cross a bridge only if the truck's weight does not exceed that capacity.
Some cities are destination cities, where customers are eager to see your truck. You start at city (which is never a destination city) and must visit all destination cities, in any order. Because you drive a single truck, its weight is fixed for the whole journey.
Determine the maximum truck weight for which you can start at city and still reach every destination city, using only bridges that can support that weight.
Input
The first line contains three positive integers , , and : the number of cities, the number of roads, and the number of destination cities. There are at most cities and at most roads.
Each of the next lines contains three integers , meaning there is a road between city and city whose bridge has a maximum weight capacity of .
Each of the next lines contains one destination city. There is at least one destination city, and city is never a destination.
Output
Print a single integer: the largest weight that can be driven from city through all destination cities.