Book of Evil

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 nm 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.

Examples

input

6 2 3
1 2
1 5
2 3
3 4
4 5
5 6

output

3

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.

Solution:

#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <memory.h>

using namespace std;

const int N = 1000010;

int ss[N], ff[N], pred[N], last[N], deep[N];
bool was[N], bad[N];
int d, ans;

void build(int v) {
was[v] = true;
deep[v] = -1;
if (bad[v]) deep[v] = 0;
int j = last[v];
while (j > 0) {
if (!was[ff[j]]) {
build(ff[j]);
if (deep[ff[j]] >= 0) {
int cur = deep[ff[j]] + 1;
if (cur > deep[v]) deep[v] = cur;
}
}
j = pred[j];
}
}

void go(int v, int up) {
if (deep[v] <= d && up <= d) ans++;
  was[v] = true;
  vector <int> values, vertices;
int j = last[v];
while (j > 0) {
if (!was[ff[j]]) {
values.push_back(deep[ff[j]] == -1 ? -1 : (2 + deep[ff[j]]));
vertices.push_back(ff[j]);
}
j = pred[j];
}
int sz = values.size();
if (sz == 0) return;
vector <int> prefmax(sz), sufmax(sz);
int mx = -1;
for (int i=0;i<sz;i++) {
    prefmax[i] = mx;
    if (values[i] > mx) mx = values[i];
}
mx = -1;
for (int i=sz-1;i>=0;i--) {
sufmax[i] = mx;
if (values[i] > mx) mx = values[i];
}
for (int i=0;i<sz;i++) {
    int newup = up == -1 ? -1 : (up + 1);
    if (prefmax[i] > newup) newup = prefmax[i];
if (sufmax[i] > newup) newup = sufmax[i];
if (bad[v] && 1 > newup) newup = 1;
go(vertices[i], newup);
}
}

int main() {
int n, m;
scanf("%d %d %d", &n, &m, &d);
for (int i=1;i<=n;i++) bad[i] = false;
  for (int i=0;i<m;i++) {
    int foo;
    scanf("%d", &foo);
    bad[foo] = true;
  }
  for (int i=1;i<=n-1;i++) {
    scanf("%d %d", ss+i, ff+i);
    ss[i + n - 1] = ff[i];
    ff[i + n - 1] = ss[i];
  }
  for (int i=1;i<=n;i++) last[i] = 0;
  for (int i=1;i<=n+n-2;i++) {
    pred[i] = last[ss[i]];
    last[ss[i]] = i;
  }
  for (int i=1;i<=n;i++) was[i] = false;
  build(1);
  for (int i=1;i<=n;i++) was[i] = false;
  ans = 0;
  go(1, -1);
  printf("%d\n", ans);
  return 0;
}