QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 256 MB Total points: 100

#339. Sentry Scout

Statistics

Xiao R and B Shen are playing a game. The map of this game consists of $n$ points and $n-1$ undirected edges. Each undirected edge connects two points, and the map is connected. In other words, the game map is a tree with $n$ nodes.

There is an item in the game called a "scout guard." When a player places a scout guard on a point, it can monitor that point and all points within a distance of $d$ from it. Here, the distance between two points is defined as their distance in the tree, which is the number of edges on the unique simple path between the two points.

Placing a scout guard on a point incurs a certain cost, and the cost of placing a guard at different points may vary. Now that Xiao R knows all the locations where B Shen might appear, please calculate the minimum cost to monitor all these locations.

Input

The first line contains two positive integers $n$ and $d$, representing the number of points on the map and the viewing range of the scout guard, respectively. The points on the map are numbered from $1$ to $n$.

The second line contains $n$ positive integers, where the $i$-th integer represents the cost $w_i$ of placing a scout guard at point $i$. It is guaranteed that $w_i \le 1000$.

The third line contains a positive integer $m$, representing the number of points where B Shen might appear. It is guaranteed that $m \le n$.

The fourth line contains $m$ positive integers, representing the indices of the points where B Shen might appear, given in increasing order without repetition.

The next $n-1$ lines each contain two positive integers $u, v$, representing an undirected edge between point $u$ and point $v$.

Output

Output a single integer representing the minimum cost required to monitor all points where B Shen might appear.

Examples

Input 1

12 2
8 9 12 6 1 1 5 1 4 8 10 6
10
1 2 3 5 6 7 8 9 10 11
1 3
2 3
3 4
4 5
4 6
4 7
7 8
8 9
9 10
10 11
11 12

Output 1

10

Note 1

Place scout guards at point 4 and point 9.

Subtasks

Test Case ID $n$ $d$ Special Properties
1 $\le 20$ $\le 5$ None
2,3 $\le 500\,000$ $= 1$ None
4,5 $\le 500\,000$ $\le 20$ $n = m$
6,7,8 $\le 10\,000$ $\le 20$ None
9,10 $\le 500\,000$ $\le 20$ None

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.