-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path337D.cpp
More file actions
62 lines (57 loc) · 1012 Bytes
/
Copy path337D.cpp
File metadata and controls
62 lines (57 loc) · 1012 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include<bits/stdc++.h>
using namespace std;
int n, m, d;
int a[100009];
int dep[4][100009];
bool vis[100009];
struct Edge{
int to, nxt;
}e[200009];
int head[100009], tot;
void add(int x, int y){
e[++tot].to = y;
e[tot].nxt = head[x];
head[x] = tot;
}
void dfs(int x, int fa, int type){
dep[type][x] = dep[type][fa] + 1;
for(int i = head[x]; i; i = e[i].nxt){
int y = e[i].to;
if(y == fa) continue;
dfs(y, x, type);
}
}
int main(){
scanf("%d%d%d", &n, &m, &d);
for(int i = 1; i <= m; i++){
scanf("%d", &a[i]);
}
for(int i = 1; i <= n - 1; i++){
int x, y;
scanf("%d%d", &x, &y);
add(x, y);
add(y, x);
}
dfs(1, 0, 1);
int x = 1;
for(int i = 1; i <= m; i++){
if(dep[1][a[i]] > dep[1][a[x]])
x = i;
}
x = a[x];
dfs(x, 0, 2);
for(int i = 1; i <= n; i++){
if(dep[2][a[i]] > dep[2][a[x]])
x = i;
}
x = a[x];
dfs(x, 0, 3);
int ans = 0;
for(int i = 1; i <= n; i++){
if(dep[2][i] - 1 <= d && dep[3][i] - 1 <= d){
ans++;
}
}
printf("%d\n", ans);
return 0;
}