Thieves
Time limit1sMemory limit1024 MB
Given a tree with K robbed cities, block some cities at cost a_i so that the reachable set of cities from the robbed nodes through unblocked cities is minimized in total cost (blocking plus M per searched city).
- Level
Hard8 of 10
- Topics
- Tree, Dynamic programming, DFS, Greedy
- Solved
- No attempts yet
Statement
There are cities numbered from to . They are connected by roads so that between any two cities there is exactly one path. In other words, the cities and roads form a tree.
A gang of thieves simultaneously robbed the shops of distinct cities. The crime happened just now, so the thieves have not fled yet, but from now on they may move freely along the roads.
Knowing this, the police can block the entrances of some cities. Once all entrances of a city are blocked, thieves can no longer enter that city; however, leaving a city can never be blocked. After blocking, the police search every city where a thief could be.
A thief could be in a city if, starting from one of the robbed cities, that city is reachable while passing only through cities whose entrances are not blocked. The robbed cities already contain a thief, so they must always be searched.
The police budget is limited. Searching one city costs , and blocking all roads leading into city costs . The police want to choose which cities to seal off so that the total cost of the operation is as small as possible.
Find the minimum possible cost of the search operation.
Input
The first line contains three integers , , and : the number of cities, the number of robbed cities, and the cost of searching one city.
Each of the next lines contains two space-separated integers and , the numbers of the two cities joined by the -th road.
The next line contains integers; the -th integer is the cost of blocking all entrances into city .
The last line contains distinct integers, the numbers of the robbed cities.
Output
Print a single integer: the minimum possible cost of the search operation.