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 ≤ 10^5, 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 a_1, a_2, ..., a_{n}, where each a_{i} 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 "x_{i} y_{i}" (without the quotes) (1 ≤ x_{i}, y_{i} ≤ n, x_{i} ≠ y_{i}), where x_{i} and y_{i} 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: $80$ 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: $88$ The restaurants are located at vertices 4, 5, 6, 7. Kefa can't go to restaurants 6, 7.

Difficulty: interview

Starter code:

Solutions:
n, m = map(int, input().split())
a = [0] + list(map(int, input().split()))
b = [0] + [set() for i in range(n) ]
k = 0
f = [0] * (n + 1)
f[1] = a[1]
for i in range(n-1):
    x, y = map(int, input().split())
    b[x].add(y)
    b[y].add(x)
    
from collections import deque
d = deque()
d.append(1)
while len(d) > 0:
    t = d.popleft()
    if len(b[t]) == 0:
        if f[t] <= m:
            k += 1
    for i in b[t]:
        b[i].remove(t)
        if a[i] == 0 and f[t] <= m:
            f[i] = 0
        else:    
            f[i] = f[t] + 1
        d.append(i)
print(k)

from collections import deque
n, m = tuple(map(int, input().split()))
is_cat = tuple(map(int, input().split()))

p = [[] for i in range(n)]
for i in range(n-1):
    x, y = list(map(int, input().split()))
    p[x - 1].append(y - 1)
    p[y - 1].append(x - 1)


q = deque([(0, is_cat[0])])
used = [0] * n
res = 0
while len(q) > 0:
    u, c = q.popleft()
    used[u] = 1
    ok = False
    for v in p[u]:
        if used[v]:
            continue
        ok = True
        if is_cat[v] and is_cat[v] + c <= m:
            q.append((v, c + is_cat[v]))
        elif not is_cat[v]:
            q.append((v, 0))
    if not ok:
        res += 1


print(res)


from collections import deque

n,m=map(int,input().split())
a=list(map(int,input().split()))
tree={}
for i in range(n-1):
	x,y=map(int, input().split())
	if x not in tree:
		tree[x]=[]
	if y not in tree:
		tree[y]=[]
	tree[x].append(y)
	tree[y].append(x)

#BFS
res=0
root=(1,a[0],0) #node,sum,from
d=deque() 
d.append(root)
while len(d)!=0:
	curr=d.popleft()
	children=tree[curr[0]]
	if len(children)==1 and curr[0]!=1: #leaf with only father, not root
		res+=1
	else:
		for child in children:
			if child==curr[2]: #father
				continue
			next_sum=0
			if a[child-1]==1:
				next_sum=curr[1]+a[child-1]
				if next_sum>m:
					continue
			
			to_add=(child,next_sum,curr[0])
			d.append(to_add)

print(res)

#!/usr/bin/env python
# 580C_park.py - Codeforces.com/problemset/problem/580/C by Sergey 2015

import unittest
import sys
import collections

###############################################################################
# Park Class (Main Program)
###############################################################################


class Node:

    def __init__(self, num, is_cat):
        self.num = num
        self.c = is_cat
        self.chs = []
        self.edgs = []

    def add_ch(self, ch):
        ch.parent = self
        self.chs.append(ch)

    def add_edge(self, e):
        e.edgs.append(self)
        self.edgs.append(e)


class Park:
    """ Park representation """

    def __init__(self, test_inputs=None):
        """ Default constructor """

        it = iter(test_inputs.split("\n")) if test_inputs else None

        def uinput():
            return next(it) if it else sys.stdin.readline().rstrip()

        # Reading single elements
        [self.n, self.m] = list(map(int, uinput().split()))

        # Reading a single line of multiple elements
        self.nums = list(map(int, uinput().split()))

        # Reading multiple lines of pairs
        pairs = (" ".join(uinput() for i in range(self.n-1))).split()
        self.numa = [int(pairs[i]) for i in range(0, 2*(self.n-1), 2)]
        self.numb = [int(pairs[i]) for i in range(1, 2*(self.n-1), 2)]

        # Building the tree
        self.nodes = []
        for i in range(self.n):
            self.nodes.append(Node(i, self.nums[i]))

        for i in range(self.n-1):
            self.nodes[self.numa[i]-1].add_edge(self.nodes[self.numb[i]-1])

    def calculate(self):
        """ Main calcualtion function of the class """

        result = 0

        # BFS
        d = collections.deque()
        d.append(self.nodes[0])
        vis = set()
        while d:
            v = d.popleft()
            vis.add(v.num)
            for e in v.edgs:
                if e.num not in vis:
                    e.parent = v
                    v.chs.append(e)
                    d.append(e)

        # BFS
        d = collections.deque()
        d.append(self.nodes[0])
        while d:
            v = d.popleft()
            if v.num == 0:
                v.cons = v.c
                v.conssf = v.cons
            else:
                p = v.parent
                if v.c:
                    v.cons = p.cons + 1
                    v.conssf = max(p.conssf, v.cons)
                else:
                    v.cons = 0
                    v.conssf = p.conssf
            d.extend(v.chs)
            if len(v.chs) == 0 and v.conssf <= self.m:
                result += 1

        return str(result)

###############################################################################
# Unit Tests
###############################################################################


class unitTests(unittest.TestCase):

    def test_single_test(self):
        """ Park class testing """

        # Constructor test
        test = "4 1\n1 1 0 0\n1 2\n1 3\n1 4"
        d = Park(test)
        self.assertEqual(d.n, 4)
        self.assertEqual(d.m, 1)
        self.assertEqual(d.numa, [1, 1, 1])
        self.assertEqual(d.numb, [2, 3, 4])
        self.assertEqual(d.nums, [1, 1, 0, 0])

        # Sample test
        self.assertEqual(Park(test).calculate(), "2")

        # Sample test
        test = "7 1\n1 0 1 1 0 0 0\n1 2\n1 3\n2 4\n2 5\n3 6\n3 7"
        self.assertEqual(Park(test).calculate(), "2")

        # Sample test
        test = "7 1\n0 0 1 1 0 0 1\n1 2\n1 3\n2 4\n2 5\n3 6\n3 7"
        self.assertEqual(Park(test).calculate(), "3")

        # My tests
        test = ""
        # self.assertEqual(Park(test).calculate(), "0")

        # Time limit test
        # self.time_limit_test(5000)

    def time_limit_test(self, nmax):
        """ Timelimit testing """
        import random
        import timeit

        # Random inputs
        test = str(nmax) + " " + str(nmax) + "\n"
        numnums = [str(i) + " " + str(i+1) for i in range(nmax)]
        test += "\n".join(numnums) + "\n"
        nums = [random.randint(1, 10000) for i in range(nmax)]
        test += " ".join(map(str, nums)) + "\n"

        # Run the test
        start = timeit.default_timer()
        d = Park(test)
        calc = timeit.default_timer()
        d.calculate()
        stop = timeit.default_timer()
        print(("\nTimelimit Test: " +
              "{0:.3f}s (init {1:.3f}s calc {2:.3f}s)".
              format(stop-start, calc-start, stop-calc)))

def __starting_point():

    # Avoiding recursion limitaions
    sys.setrecursionlimit(100000)

    if sys.argv[-1] == "-ut":
        unittest.main(argv=[" "])

    # Print the result string
    sys.stdout.write(Park().calculate())

__starting_point()

from collections import defaultdict

n, m = map(int, input().split())
cats = list(map(int, input().split()))
tree = defaultdict(list)
vst = [0]*n

for _ in range(n-1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    tree[a].append(b)
    tree[b].append(a)

ans = 0
vst[0] = True
Q = [(0, 0)]
while Q:
    now, cc = Q.pop()
    vst[now] = True
    cc = 0 if not cats[now] else cc + 1
    if cc > m:
        continue
    if now not in tree or all(vst[nxt] for nxt in tree[now]):
        if cc <= m:
            ans += 1
    for nxt in tree[now]:
        if not vst[nxt]:
            Q.append((nxt, cc))
print(ans)

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys
sys.setrecursionlimit(10**6)
import math
n, m = list(map(int,input().split()))
cats = list(map(int,input().split()))
G = [[] for i in range(n)]

for i in range(n-1):
    x,y = [int(x)-1 for x in input().split()]
    G[x].append(y)
    G[y].append(x)

q = []
q.append((0, -1, 0, 0))
count = 0
while q != []:
    u, parent, consecutive, cat_num = q.pop()

    if not cats[u]:
        consecutive = 0
    consecutive += cats[u]
    cat_num = max(consecutive, cat_num)
    if cat_num <= m and len(G[u]) == 1 and u != 0:
        count += 1

    for v in G[u]:
        if v != parent:
            q.append((v, u, consecutive, cat_num))
print(count)


"""
Codeforces Round #321 (Div. 2)

Problem 580 C. Kefa and Park

@author yamaton
@date 2015-09-22
"""

import itertools as it
import functools
import operator
import collections
import math
import sys



def solve(cats, edges, n, m):

    connected = collections.defaultdict(set)
    for a, b in edges:
        connected[a].add(b)
        connected[b].add(a)

    # This is O(n^2)...
    def connected_to(v, visited):
        return connected[v] - visited

    # print_stderr('tree:', tree)
    # print_stderr('leaves: ', leaves)

    # # n ... # of vertices
    # # m ... max # of consecutive cats still OK
    # # 1-based index

    cats = {i: cat for i, cat in enumerate(cats, 1)}

    states = {(1, cats[1])}
    visited = {1}
    count = 0
    while states:
        next_states = set()
        for s, cat_count in states:
            children = connected_to(s, visited)
            visited |= children
            if not children:
                count += 1
            for x in children:
                if cats[x]:
                    next_cat_count = cat_count + cats[x]
                else:
                    next_cat_count = 0

                if next_cat_count <= m:
                    newstate = x, next_cat_count
                    next_states.add(newstate)

        states = next_states
    return count

def print_stderr(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)


def main():
    [n, m] = [int(i) for i in input().strip().split()]
    cats = [int(i) for i in input().strip().split()]
    assert len(cats) == n
    edges = [tuple(int(i) for i in input().strip().split()) for _ in range(n-1)]
    result = solve(cats, edges, n, m)
    print(result)


def __starting_point():
    main()

__starting_point()

from collections import deque
class edge:
	def __init__(self,x,y):
		self.x = x
		self.y = y
	def other(self,x):
		if x == self.x:
			return self.y
		else:
			return self.x


n,m = list(map(int,input().split(' ')))
a = list(map(int,input().split(' ')))
adj = [ [edge(0,0) for j in range(1)] for i in range(n) ]
for i in range(n-1):
	xi,yi = list(map(int,input().split(' ')))
	adj[xi-1].append(edge(xi-1,yi-1))
	adj[yi-1].append(edge(xi-1,yi-1))

answer = 0


marked = [False]*n
pi = [-1]*n
count = [0]*n
k = 0
queue = deque()
pi[k] = k
queue.append(k)
marked[k] = True
while len(queue) > 0:
	v = queue[0]
	queue.popleft()
	if a[v] == 1 and a[pi[v]] == 1:
		count[v] = count[pi[v]]
	if a[v] == 1 : count[v] += 1
	#print("m :",m," count[v] :",count[v])
	if count[v] > m:
		marked[v] = True
		continue
	c = 0
	for e in adj[v]:
		w = e.other(v)
		if not marked[w]:
			queue.append(w)
			pi[w] = v
			marked[w] = True
	#		print(w)
			c += 1
	#print("c :", c," m :",m," pi[",v,"] " ,pi[v], " count[",v,"]:",count[v])
	if c == 0 and count[v] <= m :
		answer += 1

print(answer)







#!/usr/bin/env python
# 580C_park.py - Codeforces.com/problemset/problem/580/C by Sergey 2015

import unittest
import sys
import collections

###############################################################################
# Park Class (Main Program)
###############################################################################


class Node:

    def __init__(self, i, n):
        self.i = i
        self.n = n
        self.children = []
        self.edges = []
        self.parent = -1

    def add_child(self, c):
        c.parent = self
        self.children.append(c)

    def add_edge(self, e):
        e.edges.append(self)
        self.edges.append(e)


class Park:
    """ Park representation """

    def __init__(self, test_inputs=None):
        """ Default constructor """

        it = iter(test_inputs.split("\n")) if test_inputs else None

        def uinput():
            return next(it) if it else sys.stdin.readline().rstrip()

        # Reading single elements
        [self.n, self.m] = list(map(int, uinput().split()))

        # Reading a single line of multiple elements
        self.nums = list(map(int, uinput().split()))

        # Reading multiple number of lines of the same number of elements each
        l, s = self.n-1, 2
        inp = (" ".join(uinput() for i in range(l))).split()
        self.numm = [[int(inp[i]) for i in range(j, l*s, s)] for j in range(s)]
        self.numa, self.numb = self.numm

        # Building the tree
        self.nodes = [Node(i, self.nums[i]) for i in range(len(self.nums))]

        for i in range(len(self.numa)):
            self.nodes[self.numa[i]-1].add_edge(self.nodes[self.numb[i]-1])

    def calculate(self):
        """ Main calcualtion function of the class """

        result = 0

        # DFS to determine parent-child
        d = collections.deque([self.nodes[0]])
        visited = set()
        while d:
            v = d.pop()
            visited.add(v.i)
            for e in v.edges:
                if e.i not in visited:
                    v.add_child(e)
                    d.append(e)

        # DFS to calculate consecutive cats
        d = collections.deque([self.nodes[0]])
        while d:
            v = d.pop()
            v.cons = v.n if v.i == 0 else (v.parent.cons + 1 if v.n else 0)
            if v.cons <= self.m:
                d.extend(v.children)
                if not v.children:
                    result += 1

        return str(result)

###############################################################################
# Unit Tests
###############################################################################


class unitTests(unittest.TestCase):

    def test_single_test(self):
        """ Park class testing """

        # Constructor test
        test = "4 1\n1 1 0 0\n1 2\n1 3\n1 4"
        d = Park(test)
        self.assertEqual(d.n, 4)
        self.assertEqual(d.m, 1)
        self.assertEqual(d.numa, [1, 1, 1])
        self.assertEqual(d.numb, [2, 3, 4])
        self.assertEqual(d.nums, [1, 1, 0, 0])

        # Sample test
        self.assertEqual(Park(test).calculate(), "2")

        # Sample test
        test = "7 1\n1 0 0 1 0 0 1\n1 2\n1 7\n2 4\n2 5\n6 3\n7 3"
        self.assertEqual(Park(test).calculate(), "2")

        # Sample test
        test = "7 1\n0 0 1 1 0 0 1\n1 2\n1 3\n2 4\n2 5\n3 6\n3 7"
        self.assertEqual(Park(test).calculate(), "3")

        # My tests
        test = ""
        # self.assertEqual(Park(test).calculate(), "0")

        # Time limit test
        # self.time_limit_test(5000)

    def time_limit_test(self, nmax):
        """ Timelimit testing """
        import random
        import timeit

        # Random inputs
        test = str(nmax) + " " + str(nmax) + "\n"
        numnums = [str(i) + " " + str(i+1) for i in range(nmax)]
        test += "\n".join(numnums) + "\n"
        nums = [random.randint(1, 10000) for i in range(nmax)]
        test += " ".join(map(str, nums)) + "\n"

        # Run the test
        start = timeit.default_timer()
        d = Park(test)
        calc = timeit.default_timer()
        d.calculate()
        stop = timeit.default_timer()
        print(("\nTimelimit Test: " +
              "{0:.3f}s (init {1:.3f}s calc {2:.3f}s)".
              format(stop-start, calc-start, stop-calc)))

def __starting_point():

    # Avoiding recursion limitaions
    sys.setrecursionlimit(100000)

    if sys.argv[-1] == "-ut":
        unittest.main(argv=[" "])

    # Print the result string
    sys.stdout.write(Park().calculate())

__starting_point()

n, m = map(int, input().split())
cats = list(map(int, input().split()))
graf = [[] for i in range(n)]
ans = 0
for i in range(n - 1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    graf[a].append(b)
    graf[b].append(a)
q = [(0, 0, 0)]
while len(q) != 0:
    v, catind, prev = q.pop()
    if cats[v]:
        catind += 1
    else:
        catind = 0
    if catind > m:
        continue
    if len(graf[v]) == 1 and v:
        ans += 1
        continue
    for i in graf[v]:
        if i == prev: continue
        q.append((i, catind, v))
print(ans)

def main():
    dfs(1, cat_in[1])
    print(ans)    
    
def dfs(v, c):
    nonlocal ans
    used[v] = True
    if cat_in[v]:
        if c > m:
            return
    else:
        c = 0
    q = 0
    
    for x in arr[v]:
        if not used[x]:
            dfs(x, c + cat_in[x])
            q += 1
    if q == 0 and v != 1:
        ans += 1     

n, m = list(map(int, input().split()))
cat_in = [0] + [int(x) for x in input().split()]
arr = [set() for x in range(n+1)]
for i in range(n-1):
    a, b = list(map(int, input().split()))
    arr[a].add(b)
    arr[b].add(a)
used = [False] * (n + 1)
ans = 0
import sys, threading
sys.setrecursionlimit(10**8)
threading.stack_size(25 * 10**6)
thread = threading.Thread(target = main)
thread.start()

#main()


def param(x, y):
	if y == 0: 
		return y
	return x

def bfs():
	nonlocal ans
	q = queue.Queue()
	dist[0] = cats[0]
	q.put(1)
	while not q.empty():
		curr = q.get()
		cats[curr - 1] = -1
		if dist[curr - 1] > limit:
			continue
		if len(graph[curr]) == 1 and curr != 1:
			ans += 1
		for neighbor in graph[curr]:
			if cats[neighbor - 1] != -1:
				dist[neighbor - 1] = param(dist[curr - 1] + cats[neighbor - 1], cats[neighbor - 1])
				q.put(neighbor)
	

from sys import stdin
import queue
live = True
if not live: stdin = open('data.in', 'r')

n, limit = list(map(int, stdin.readline().strip().split()))
cats = list(map(int, stdin.readline().strip().split()))
dist = [0] * n
graph = {}
for it in range(1, n):
	x, y = list(map(int, stdin.readline().strip().split()))
	if graph.get(x) == None:
		graph[x] = []
	graph[x] += [y]
	if graph.get(y) == None:
		graph[y] = []
	graph[y] += [x]

ans = 0
bfs()
print(ans)

if not live: stdin.close()

n,m=map(int,input().split())
f=[0]+list(map(int,input().split()))
z=[1]+[0]*(n+1)
e=[[] for i in range(n+1)]
for i in range(1,n):
    po,ki=map(int,input().split())
    e[po].append(ki)
    e[ki].append(po)
e[1]+=[0]
r=[len(x)==1 for x in e]
ans=0
s={(1,0)}
while len(s):
    po,ki=s.pop()
    z[po]=1
    if f[po]: ki+=1
    else: ki=0
    if ki>m: continue
    if r[po]: ans+=1
    for x in e[po]:
        if z[x]: continue
        s|={(x,ki)}
print(ans)

n,m=map(int,input().split())
f=[0]+list(map(int,input().split()))
z=[1]+[0]*(n+1)
e=[[] for i in range(n+1)]
for i in range(1,n):
    po,ki=map(int,input().split())
    e[po].append(ki)
    e[ki].append(po)
e[1]+=[0]
r=[len(x)==1 for x in e]
ans=0
s={(1,0)}
while s!=set():
    po,ki=s.pop()
    z[po]=1
    if f[po]: ki+=1
    else: ki=0
    if ki>m: continue
    if r[po]: ans+=1
    for x in e[po]:
        if z[x]: continue
        s|={(x,ki)}
print(ans)

n,m=map(int,input().split())
f=[0]+list(map(int,input().split()))
z=[1]+[0]*(n+1)
e=[[] for i in range(n+1)]
for i in range(1,n):
    po,ki=map(int,input().split())
    e[po].append(ki)
    e[ki].append(po)
e[1]+=[0]
r=[len(x)==1 for x in e]
ans=0
s=[(1,0)]
while len(s):
    po,ki=s.pop()
    z[po]=1
    if f[po]: ki+=1
    else: ki=0
    if ki>m: continue
    if r[po]: ans+=1
    for x in e[po]:
        if z[x]: continue
        s+=[(x,ki)]
print(ans)

n,m=map(int,input().split())
f=[0]+list(map(int,input().split()))
z=[1]+[0]*(n+1)
e=[[] for i in range(n+1)]
for i in range(1,n):
    po,ki=map(int,input().split())
    e[po].append(ki)
    e[ki].append(po)
e[1]+=[0]
r=[len(x)==1 for x in e]
ans=0
kil=1
s=[(1,0)]
while kil:
    po,ki=s.pop()
    z[po]=1
    kil-=1
    if f[po]: ki+=1
    else: ki=0
    if ki>m: continue
    if r[po]: ans+=1
    for x in e[po]:
        if z[x]: continue
        s+=[(x,ki)]
        kil+=1
print(ans)

n, m = list(map(int, input().split()))
has_cat = [None] + [x == 1 for x in map(int, input().split())]

neighbors = [[] for i in range(n + 1)]
for i in range(n - 1):
  u, v = list(map(int, input().split()))
  neighbors[u].append(v)
  neighbors[v].append(u)

seen = [False for i in range(n + 1)]

count = 0

queue = [(0, 1)]
tail = 0
while tail < len(queue):
  cats, u = queue[tail]
  tail += 1
  seen[u] = True
  if has_cat[u]:
    cats += 1
    if cats > m:
      continue
  else:
    cats = 0

  is_leaf = True
  for v in neighbors[u]:
    if not seen[v]:
      is_leaf = False
      queue.append((cats, v))

  if is_leaf:
    count += 1

print(count)



from collections import defaultdict
from collections import namedtuple

State = namedtuple('State', ['node', 'remain', 'parent'])

n, m = [int(x) for x in input().split()]
cats = [int(x) for x in input().split()]

graph = defaultdict(set)
for _ in range(n - 1):
    i, j = [int(x) - 1 for x in input().split()]
    graph[i].add(j)
    graph[j].add(i)

ans = 0
stack = [State(0, m, None)]
while stack:
    st = stack.pop()
    rem = st.remain - 1 if cats[st.node] else m
    if rem >= 0:
        num_of_children = 0
        for child in graph[st.node]:
            if child != st.parent:
                stack.append(State(child, rem, st.node))
                num_of_children += 1
        if num_of_children == 0:
            ans += 1

print(ans)


__author__ = 'User'
n, m = list(map(int, input().split()))
cat = [0] + list(map(int, input().split()))
arr = [[] for i in range(n + 1)]
for i in range(n - 1):
    a, b = list(map(int, input().split()))
    arr[a].append(b)
    arr[b].append(a)
counter = [0] * n
c = 0
i = 0
queue = [(1, 0)]
#print(arr)
while i < len(queue):
    j = 0
    if len(arr[queue[i][0]]) == 1 and queue[i][1] == arr[queue[i][0]][0]:
        c += 1
    else:
        for j in arr[queue[i][0]]:
            if j != queue[i][1]:
                if cat[j] != 0:
                    cat[j] += cat[queue[i][0]]
                if cat[j] <= m:
                    queue.append((j, queue[i][0]))
    i += 1
print(c)
#print(queue)
#print(cat)
#print(arr)


def intline():
    return [int(s) for s in input().split()]

# number of vertices in tree
# acceptable number of consecutive cat vertices
n, m = intline()

# cat vertices
a = [0] + intline()

# read tree structure
tree = {}
for i in range(n - 1):
    x, y = intline()

    if x not in tree:
        tree[x] = []
    if y not in tree:
        tree[y] = []

    tree[x].append(y)
    tree[y].append(x)

# dfs from root down to every leaf
seen = [False] * (n + 1)
work = [(1, 0)]
paths = 0
while work:
    cur, run = work.pop()

    # already visited, no more leaves down here
    if seen[cur]:
        continue
    seen[cur] = True

    # calculate the current run
    if a[cur]:
        run += 1
    else:
        run = 0

    # more than the allowed number of consecutive cat vertices
    if run > m:
        continue

    # leaf, only has an edge to the parent
    if len(tree[cur]) == 1 and cur != 1:
        paths += 1
        continue

    for neighbour in tree[cur]:
        work.append([neighbour, run])

print(paths)


from collections import deque

n,m = list(map(int,input().split()))
cat =[0] + list(map(int,input().split()))
path = [0] + [set() for _ in range(n)]
dp = [0] * (n+1)
for _ in range(n-1):
    x, y = list(map(int , input().split()))
    path[x].add(y)
    path[y].add(x)

d = deque()

d.append(1)
dp[1] = cat[1]
ans = 0
while len(d) > 0:
    t = d.popleft()
    if dp[t] > m :
        continue
    if len(path[t]) == 0:
        if dp[t] <= m:
            ans+=1
    for x in path[t]:
        path[x].remove(t)
        d.append(x)
        if cat[x] != 0:
            dp[x] = dp[t] + cat[x]
        else:
            dp[x] = 0

print(ans)


def fill(e, f, g):
    n = [g]
    while n:
        d = n.pop()
        for p in e[d]:
            if len(f[p]) == 0:
                f[d].add(p)
                n.append(p)

def count_cats(f, a, m, n, c):
    s = 0
    nodes = [(n, c)]
    while nodes:
        n, c = nodes.pop()
        z = a[n]
        t = z + c if z else 0
        if t <= m:
            if len(f[n]) == 0:
                s += 1
            else:
                for j in f[n]:
                    nodes.append((j, t))
    return s

def solve(n, m, a, e):
    f = []
    for i in range(n):
        f.append(set())
    fill(e, f, 0)
    s = count_cats(f, a, m, 0, 0)
    return s

def main():
    n,m = list(map(int,input().split()))
    a = list(map(int,input().split()))
    e = []
    for i in range(n):
        e.append(set())
    for i in range(n-1):
        p = tuple(map(int, input().split()))
        e[p[0]-1].add(p[1]-1)
        e[p[1]-1].add(p[0]-1)
    print(solve(n, m, a, e))


def __starting_point():
    main()

__starting_point()

from collections import deque
n, m = tuple(map(int, input().split()))
l = [0] + list(map(int, input().split()))
graph = [set() for i in range(n + 1)]
for i in range(n - 1):
    a, b = tuple(map(int, input().split()))
    graph[a].add(b)
    graph[b].add(a)
#islist = [0] * (n + 1)
maxcats = [0] * (n + 1)
cats = [0] * (n + 1)
checked = [0] * (n + 1)
q = deque()
q.append((1, 0, 0))
res = 0

while len(q) > 0:
    
    ij = q.popleft()
    i = ij[0]
    j = ij[1]
    maxi = ij[2]
    checked[i] = 1
    if l[i]: j += 1
    else: j = 0
    if maxi < j: maxi = j
    islist = 1
    for elem in graph[i]:
        #print(elem)
        if not checked[elem]: 
            
            q.append((elem, j, maxi))
            islist = 0
    if islist:
        
        if maxi <= m:
            res += 1
print(res)    

n, m = input().split()
n, m = int(n), int(m)
a = list( map( int , input().split() ) )
v = [ [] for _ in range( n ) ]
for i in range( n - 1 ):
  x = list( map( int , input().split() ) )
  x[ 0 ], x[ 1 ] = int(x[ 0 ]) - 1, int(x[ 1 ]) - 1
  v[ x[ 0 ] ].append( x[ 1 ] )
  v[ x[ 1 ] ].append( x[ 0 ] )
tag = [False] * n
con = [0] * n
from collections import deque as dq
d = dq()
d.append( 0 )
con[ 0 ] = a[ 0 ]
tag[ 0 ] = True
ans = 0
while len(d) > 0:
  x, chd = d.popleft(), 0
  #  print( ( x , con[ x ] ) )
  if con[ x ] > m: continue
  for y in v[x]:
    if not tag[ y ]:
      con[ y ] = con[ x ] + a[ y ] if a[ y ] == 1 else 0
      tag[ y ] = True
      chd += 1
      d.append( y )
  if chd == 0 and con[ x ] <= m:
    ans += 1
print( ans )