Kefa decided to celebrate his first big salary by going to the restaurant.
He lives by an unusual park. The park is a rooted tree consisting of n vertices with the root at vertex 1. Vertex 1 also contains Kefa's house. Unfortunaely for our hero, the park also contains cats. Kefa has already found out what are the vertices with cats in them.
The leaf vertices of the park contain restaurants. Kefa wants to choose a restaurant where he will go, but unfortunately he is very afraid of cats, so there is no way he will go to the restaurant if the path from the restaurant to his house contains more than m consecutive vertices with cats.
Your task is to help Kefa count the number of restaurants where he can go.
Input
The first line contains two integers, n and m (2 ≤ n ≤ 105, 1 ≤ m ≤ n) — the number of vertices of the tree and the maximum number of consecutive vertices with cats that is still ok for Kefa.
The second line contains n integers a1, a2, ..., an, where each ai either equals to 0(then vertex i has no cat), or equals to 1 (then vertex i has a cat).
Next n - 1 lines contains the edges of the tree in the format "xi yi" (without the quotes) (1 ≤ xi, yi ≤ n, xi ≠ yi), where xi and yi are the vertices of the tree, connected by an edge.
It is guaranteed that the given set of edges specifies a tree.
Output
A single integer — the number of distinct leaves of a tree the path to which from Kefa's home contains at most m consecutive vertices with cats.
Examples
Input
4 1
1 1 0 0
1 2
1 3
1 4
Output
2
Input
7 1
1 0 1 1 0 0 0
1 2
1 3
2 4
2 5
3 6
3 7
Output
2
Note
Let us remind you that a tree is a connected graph on n vertices and n - 1 edge. A rooted tree is a tree with a special vertex called root. In a rooted tree among any two vertices connected by an edge, one vertex is a parent (the one closer to the root), and the other one is a child. A vertex is called a leaf, if it has no children.
Note to the first sample test: The vertices containing cats are marked red. The restaurants are at vertices 2, 3, 4. Kefa can't go only to the restaurant located at vertex 2.
Note to the second sample test: The restaurants are located at vertices 4, 5, 6, 7. Kefa can't go to restaurants 6, 7.
题意:有一颗树,从根出发到叶节点的路径中,路径上不能有大于m个连续的红色的节点,符合这个条件的路径有几条?
//emmmm为什么建一个从根到叶的单向边wa,建双向边就A了。。。
此题主要是给自己提个醒,然后记下找叶节点的方法
单向边:head[x]==-1时为叶节点
双向边:就如程序所示咯
#include
#include
#include
using namespace std;
typedef long long ll;
const int maxn=100009;
int book[maxn],head[maxn],cnt,n,m,ans;
struct node{
int id;
int next;
}side[2*maxn];
void init()
{
memset(head,-1,sizeof(head));
cnt=0;
}
void add(int x,int y)
{
side[cnt].id=y;
side[cnt].next=head[x];
head[x]=cnt++;
}
void dfs(int x,int fa,int num)
{
if(num>m) return ;
int flag=0;//标记是否是叶节点
for(int i=head[x];i!=-1;i=side[i].next)
{
int y=side[i].id;
if(y==fa) continue;
flag=1;//表示该节点有子节点
if(book[y])
dfs(y,x,num+1);
else
dfs(y,x,0);
}
if(!flag&&num<=m)//flag==0表示没有叶节点
ans++;
}
int main()
{
scanf("%d%d",&n,&m);
init();
for(int i=1;i<=n;i++)
scanf("%d",&book[i]);
for(int i=1;i