Codeforces Round 196 (Div. 2)
D
Book of Evil
Codeforces
2000
原题
← CE →
翻译中…

Paladin Manao caught the trail of the ancient Book of Evil in a swampy area. This area contains $*n*$ settlements numbered from 1 to $*n*$. Moving through the swamp is very difficult, so people tramped exactly $*n* - 1$ paths. Each of these paths connects some pair of settlements and is bidirectional. Moreover, it is possible to reach any settlement from any other one by traversing one or several paths.

翻译中…

The distance between two settlements is the minimum number of paths that have to be crossed to get from one settlement to the other one. Manao knows that the Book of Evil has got a damage range $*d*$. This means that if the Book of Evil is located in some settlement, its damage (for example, emergence of ghosts and werewolves) affects other settlements at distance $*d*$ or less from the settlement where the Book resides.

翻译中…

Manao has heard of $*m*$ settlements affected by the Book of Evil. Their numbers are $*p*_{1}, *p*_{2}, ..., *p*_{*m*}$. Note that the Book may be affecting other settlements as well, but this has not been detected yet. Manao wants to determine which settlements may contain the Book. Help him with this difficult task.

翻译中…

Input

翻译中…

The first line contains three space-separated integers $*n*$, $*m*$ and $*d*$ ($1 ≤ *m* ≤ *n* ≤ 100000; 0 ≤ *d* ≤ *n* - 1$). The second line contains $*m*$ distinct space-separated integers $*p*_{1}, *p*_{2}, ..., *p*_{*m*}$ ($1 ≤ *p*_{*i*} ≤ *n*$). Then $*n* - 1$ lines follow, each line describes a path made in the area. A path is described by a pair of space-separated integers $*a*_{*i*}$ and $*b*_{*i*}$ representing the ends of this path.

翻译中…

Output

翻译中…

Print a single number — the number of settlements that may contain the Book of Evil. It is possible that Manao received some controversial information and there is no settlement that may contain the Book. In such case, print 0.

翻译中…

Note

翻译中…

Sample 1. The damage range of the Book of Evil equals 3 and its effects have been noticed in settlements 1 and 2. Thus, it can be in settlements 3, 4 or 5.

翻译中…

image

翻译中…

样例

Input #1
6 2 3
1 2
1 5
2 3
3 4
4 5
5 6
Output #1
3
InputCopy OutputCopy
题目信息
题号
337D
时间限制
2 s
内存限制
256 MB
标签
DFS 及类似
分治
动态规划
树

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。