This page is still under construction.

Parts of this page are still being built. What you see may change.

Thieves

Time limit1sMemory limit1024 MB

Summary
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 NN cities numbered from 11 to NN. They are connected by N−1N-1 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 KK 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 KK 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 MM, and blocking all roads leading into city ii costs aia_i. 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 NN, KK, and MM: the number of cities, the number of robbed cities, and the cost of searching one city.

Each of the next N−1N-1 lines contains two space-separated integers bib_i and cic_i, the numbers of the two cities joined by the ii-th road.

The next line contains NN integers; the ii-th integer aia_i is the cost of blocking all entrances into city ii.

The last line contains KK distinct integers, the numbers of the robbed cities.

Output

Print a single integer: the minimum possible cost of the search operation.

Constraints

  • 3≤N≤5000003 \le N \le 500000
  • 1≤bi,ci≤N1 \le b_i, c_i \le N
  • 1≤K≤N1 \le K \le N
  • 1≤M≤10000001 \le M \le 1000000
  • 1≤ai≤10000001 \le a_i \le 1000000

Examples1

  1. Example 1

    Input
    6 3 2
    1 2
    2 3
    2 4
    4 5
    5 6
    1 3 2 1 3 1
    1 4 6
    
    Expected output
    11