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.

Source: codeforces | Difficulty: MEDIUM
Tags: Tree algorithms

Graph algorithms

Graph traversal


Solutions:
import sys
(n, m) = map(int, input().split())
adj = [[] for i in range(n)]
a = list(map(int, input().split()))
for i in range(n - 1):
	(u, v) = map(int, input().split())
	adj[v - 1].append(u - 1)
	adj[u - 1].append(v - 1)

def dfs(v, c):
	st = [[v, c, -1]]
	ans = 0
	while len(st):
		(v, c, f) = st.pop()
		if c > m:
			continue
		if len(adj[v]) == 1 and v != 0:
			ans += 1
		for u in adj[v]:
			if u != f:
				st.append([u, (c + 1) * a[u], v])
	return ans
print(dfs(0, a[0]))


__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)]
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)


from sys import stdin

class Graph:

	def __init__(self, root, vertices, edges):
		self.size = len(vertices)
		self.vertices = vertices
		self.edges = list(map(lambda x: list(), range(self.size)))
		for (a, b) in edges:
			self.edges[a].append(b)
			self.edges[b].append(a)
		self.root = root
		self.isleaf = list(map(lambda p: p[0] != root and len(p[1]) == 1, enumerate(self.edges)))

	def solve(self, m):
		ans = 0
		label = [(False, False) for x in range(self.size)]
		stack = [(self.root, 0)]
		label[self.root] = (label[self.root][0], True)
		while len(stack) > 0:
			(node, cats) = stack.pop()
			label[node] = (True, False)
			flag = cats + 1 if self.vertices[node] == 1 else 0
			if self.isleaf[node]:
				if flag <= m:
					ans += 1
			elif flag <= m:
				for nxt in self.edges[node]:
					if label[nxt] == (False, False):
						stack.append((nxt, flag))
						label[nxt] = (label[nxt][0], True)
		return ans

def edgeMapping(line):
	(a, b) = tuple(map(int, line.split()))
	return (a - 1, b - 1)
(n, m) = tuple(map(int, input().split()))
verices = list(map(int, input().split()))
edges = list(map(edgeMapping, stdin.readlines()))
graph = Graph(0, verices, edges)
print(graph.solve(m))


from collections import defaultdict
(n, m) = map(int, input().split())
a = list(map(int, input().split()))
b = [0] * n
d = defaultdict(set)
for i in range(n - 1):
	(x, y) = map(int, input().split())
	d[x - 1].add(y - 1)
	d[y - 1].add(x - 1)
cnt = 0
s = {0}
b[0] = a[0]
prev = set()
while s:
	new_s = set()
	for el in s:
		children = d[el] - prev
		if children:
			for next_el in children:
				b[next_el] = b[el] + 1 if a[next_el] else 0
				if b[next_el] <= m:
					new_s.add(next_el)
		elif b[el] <= m:
			cnt += 1
	prev = s
	s = new_s
print(cnt)


from collections import defaultdict
(n, m) = list(map(int, input().split()))
ass = list(map(int, input().split()))
edges = defaultdict(set)
for _ in range(n - 1):
	(x, y) = list(map(int, input().split()))
	edges[x - 1].add(y - 1)
	edges[y - 1].add(x - 1)
res = 0
cats = [-1] * n
cats[0] = ass[0]
q = [0]
while q:
	k = q.pop(0)
	if cats[k] <= m:
		for x in edges[k]:
			if cats[x] == -1:
				cats[x] = (cats[k] + ass[x]) * ass[x]
				q.append(x)
		if k != 0 and len(edges[k]) < 2:
			res += 1
print(res)


from sys import stdin, stdout
from collections import deque
st = lambda : list(stdin.readline().strip())
li = lambda : list(map(int, stdin.readline().split()))
mp = lambda : map(int, stdin.readline().split())
inp = lambda : int(stdin.readline())
pr = lambda n: stdout.write(str(n) + '\n')
mod = 1000000007

def solve():
	(n, m) = mp()
	l = li()
	l = [-1] + l
	d = {i: [] for i in range(n + 1)}
	v = [False for i in range(n + 1)]
	for i in range(n - 1):
		(a, b) = mp()
		d[a].append(b)
		d[b].append(a)
	now = l[1]
	ans = 0
	q = deque()
	q.append((1, now))
	v[1] = True
	while q:
		(a, b) = q.popleft()
		f = 0
		v[a] = True
		for i in d[a]:
			c = b
			if not v[i]:
				f = 1
				v[i] = True
				if l[i] == 0:
					c = 0
				else:
					c += 1
				if c <= m:
					q.append((i, c))
		if f == 0:
			ans += 1
	pr(ans)
for _ in range(1):
	solve()


from collections import deque
(n, m) = list(map(int, input().split(' ')))
dic = {}
res = {}
cat = [0] * n
check = [0] * n
numofchild = {}
catcount = {}
temp = list(map(int, input().split(' ')))
i = 0
for x in temp:
	cat[i] = x
	dic[i] = []
	numofchild[i] = 0
	catcount[i] = 0
	res[i] = 0
	i += 1
for x in range(n - 1):
	temp = list(map(int, input().split(' ')))
	temp.sort()
	dic[temp[0] - 1].append(temp[1] - 1)
	dic[temp[1] - 1].append(temp[0] - 1)
st = deque()
st.append(0)
while len(st) != 0:
	for x in dic[st[0]]:
		st.append(x)
		del dic[x][dic[x].index(st[0])]
	st.popleft()
st.append(0)
if cat[0] == 1:
	catcount[0] = 1
while len(st) != 0:
	if len(dic[st[-1]]) == 0 or numofchild[st[-1]] >= len(dic[st[-1]]):
		if len(dic[st[-1]]) == 0:
			if catcount[st[-1]] <= m and st[-1] != 0:
				res[st[-1]] += 1
		temp = st.pop()
		check[temp] = 1
	else:
		i = numofchild[st[-1]]
		while i < len(dic[st[-1]]):
			if check[dic[st[-1]][i]] == 1:
				numofchild[st[-1]] = i + 1
				i += 1
				continue
			else:
				numofchild[st[-1]] = i + 1
				if cat[dic[st[-1]][i]] == 1:
					catcount[dic[st[-1]][i]] = catcount[st[-1]] + 1
					if catcount[dic[st[-1]][i]] > m:
						numofchild[dic[st[-1]][i]] = len(dic[dic[st[-1]][i]])
				else:
					catcount[dic[st[-1]][i]] = 0
				st.append(dic[st[-1]][i])
				break
print(list(res.values()).count(1))


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)

	def connected_to(v, visited):
		return connected[v] - visited
	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)
main()


class Stack(object):

	def __init__(self):
		self.items = []

	def push(self, new):
		self.items.append(new)

	def pop(self):
		return self.items.pop()

	def peek(self):
		return self.items[-1]

	def empty(self):
		return self.items == []

	def size(self):
		return len(self.items)
(n, m) = map(int, input().split())
Cat = [int(s) for s in input().split()]
L = [[] for i in range(n)]
for i in range(n - 1):
	(a, b) = map(int, input().split())
	L[a - 1].append(b - 1)
	L[b - 1].append(a - 1)
S = Stack()
visited = [False for i in range(n)]
S.push(0)
visited[0] = True
nbcat = [0 for i in range(n)]
nbcat[0] = Cat[0]
rest = 0
while not S.empty():
	r = S.pop()
	bool = False
	for i in L[r]:
		bool = bool or not visited[i]
		if nbcat[r] + Cat[i] <= m and (not visited[i]):
			S.push(i)
			visited[i] = True
			if Cat[i] == 1:
				nbcat[i] = nbcat[r] + Cat[i]
			else:
				nbcat[i] = 0
	if not bool:
		rest += 1
print(rest)


import sys

def input():
	return sys.stdin.readline().strip()
(n, m) = map(int, input().split())
a = [int(i) for i in input().split()]
edge = [[] for i in range(n)]
for i in range(n - 1):
	(x, y) = map(int, input().split())
	edge[x - 1].append(y - 1)
	edge[y - 1].append(x - 1)
visited = [0 for i in range(n)]
cur = edge[0]
count = [0 for i in range(n)]
if a[0]:
	count[0] += 1
for i in range(len(cur)):
	count[cur[i]] += count[0]
visited[0] = 1
total = 0
while len(cur) > 0:
	pos = cur.pop()
	visited[pos] = 1
	if a[pos]:
		count[pos] += 1
		if count[pos] <= m:
			for i in range(len(edge[pos])):
				if not visited[edge[pos][i]]:
					visited[edge[pos][i]] = 1
					cur.append(edge[pos][i])
					count[edge[pos][i]] += count[pos]
	else:
		for i in range(len(edge[pos])):
			if not visited[edge[pos][i]]:
				visited[edge[pos][i]] = 1
				cur.append(edge[pos][i])
	if len(edge[pos]) == 1 and count[pos] <= m:
		total += 1
print(total)


def kefa(n, m, cats, adjlist):
	from queue import Queue
	visited = [False for _ in range(n + 1)]
	cats_count = [-1 for _ in range(n + 1)]
	q = Queue()
	q.put(1)
	cats_count[1] = cats[0]
	visited[1] = True
	count = 0
	while q.empty() == False:
		node = q.get()
		adj = adjlist[node]
		count_visit = 0
		for c in adj:
			if visited[c] == False:
				count_visit += 1
				if cats[c - 1] == 0:
					cats_count[c] = 0
				else:
					cats_count[c] = cats_count[node] + 1
				visited[c] = True
				if cats_count[c] <= m:
					q.put(c)
		if count_visit == 0:
			count += 1
	print(count)
(n, m) = map(int, input().strip().split(' '))
cats = list(map(int, input().strip().split(' ')))
adjlist = [[] for _ in range(n + 1)]
for _ in range(n - 1):
	(x, y) = map(int, input().strip().split(' '))
	adjlist[x].append(y)
	adjlist[y].append(x)
kefa(n, m, cats, adjlist)


(n, m) = [int(i) for i in input().split()]
cat = [0] + [int(i) for i in input().split()]
d = {}
t = 1
for i in range(n - 1):
	(x, y) = [int(_) for _ in input().split()]
	try:
		d[x].append(y)
	except:
		d[x] = [y]
	try:
		d[y].append(x)
	except:
		d[y] = [x]
rec = [(1, 0, 1)]
cnt = 0
while len(rec) != 0:
	(i, c, prev) = rec.pop()
	if cat[i]:
		c += 1
	else:
		c = 0
	if c > m:
		continue
	if i != 1 and len(d[i]) == 1:
		cnt += 1
		continue
	for j in d[i]:
		if j == prev:
			continue
		rec.append((j, c, i))
print(cnt)


class Vertex:

	def __init__(self, num, is_cat):
		self.num = num
		self.cat = is_cat
		self.neighbours = []
		self.cat_count = is_cat

	def add_neighbour(self, num):
		self.neighbours.append(num)
		points[num].neighbours.append(self.num)
(n, k) = [int(i) for i in input().split()]
points = [Vertex(i, int(val)) for (i, val) in enumerate(input().split())]
for i in range(n - 1):
	(a, b) = [int(i) for i in input().split()]
	points[a - 1].add_neighbour(b - 1)

def fix_children(p):
	for c in p.neighbours:
		child = points[c]
		if child.cat:
			child.cat_count += p.cat_count
		child.neighbours = list(set(child.neighbours) - set([p.num]))
stack = points[0].neighbours
count = 0
fix_children(points[0])
used = set([0])
while stack:
	p = points[stack.pop(0)]
	fix_children(p)
	if p.cat_count <= k:
		if not p.neighbours:
			count += 1
		else:
			stack += p.neighbours
print(count)


from collections import deque
(n, m) = map(int, input().strip().split(' '))
cats = list(map(int, input().strip().split(' ')))
adj = [[] for _ in range(n)]
for _ in range(n - 1):
	(v1, v2) = map(int, input().strip().split(' '))
	adj[v1 - 1].append(v2 - 1)
	adj[v2 - 1].append(v1 - 1)

def dfs(v, g):
	res = 0
	visited = set()
	q = deque()
	q.append((v, cats[v]))
	while q:
		(curr_v, _cats) = q.pop()
		if _cats > m:
			continue
		visited.add(curr_v)
		has_ch = False
		for neib in adj[curr_v]:
			if neib not in visited:
				q.append((neib, _cats + 1 if cats[neib] else 0))
				has_ch = True
		if not has_ch:
			res += 1
	return res
print(dfs(0, adj))


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

def bfs():
	global 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())
cat = list(map(int, input().split()))
g = [[] for i in range(n)]
vis = [0 for i in range(n)]
ans = 0
for i in range(n - 1):
	(x, y) = map(int, input().split())
	g[x - 1].append(y - 1)
	g[y - 1].append(x - 1)
vis[0] = 1
que = [(-1, 0, cat[0])]
pos = 0
while pos < len(que):
	(last, x, num) = que[pos]
	pos += 1
	flag = 1
	for i in g[x]:
		if not vis[i]:
			vis[i] = True
			flag = 0
			if cat[i] + num <= m:
				if cat[i] == 0:
					que.append((x, i, 0))
				else:
					que.append((x, i, num + cat[i]))
	ans += flag
print(ans)


def BFS(s, graph, visited, cats, dist, path, leaf, isOk):
	dist[s] = cats[s]
	q = [s]
	visited[s] = True
	while len(q) > 0:
		u = q.pop(0)
		checkLeaf = True
		for i in range(len(graph[u])):
			v = graph[u][i]
			if visited[v] is False:
				checkLeaf = False
			if visited[v] is False and dist[u] + cats[v] <= isOk:
				q.append(v)
				visited[v] = True
				if cats[v] == 0:
					dist[v] = 0
				else:
					dist[v] = dist[u] + cats[v]
				path[v] = u
		if checkLeaf is True:
			leaf.append(u)
first = list(map(int, input().split()))
n = first[0]
catOk = first[1]
cats = list(map(int, input().split()))
start = 0
graph = [[] for y in range(n)]
visited = [False] * n
dist = [0] * n
path = [-1] * n
leaf = []
for x in range(n - 1):
	data = list(map(int, input().split()))
	u = data[0] - 1
	v = data[1] - 1
	graph[u].append(v)
	graph[v].append(u)
BFS(start, graph, visited, cats, dist, path, leaf, catOk)
print(len(leaf))


from sys import stdin, stderr

def readInts():
	return map(int, stdin.readline().strip().split())

def print_err(*args, **kwargs):
	print(*args, file=stderr, **kwargs)

def solve(t, cats, maxcats):
	remain = [(1, 1, cats[1])]
	out = 0
	while remain:
		(parent, node, cats_consec) = remain.pop()
		if cats_consec > maxcats:
			continue
		leaf = True
		for nn in t[node]:
			if nn == parent:
				continue
			leaf = False
			c = cats[nn]
			if c:
				nn_catscon = cats_consec + cats[nn]
			else:
				nn_catscon = 0
			remain.append((node, nn, nn_catscon))
		if leaf:
			out += 1
	return out

def run():
	(n, m) = readInts()
	cats = [0] + list(readInts())
	t = [[] for _ in range(n + 1)]
	for _ in range(n - 1):
		(a, b) = readInts()
		t[a].append(b)
		t[b].append(a)
	print(solve(t, cats, m))
run()


(n, m) = [int(i) for i in input().split()]
cat = [int(i) for i in input().split()]
m += 1
import copy
d = {1: cat[0]}
s = [set([]) for i in range(n + 1)]
for o in range(n - 1):
	(a, b) = [int(i) for i in input().split()]
	s[a].add(b)
	s[b].add(a)
leaf = []
x = set([1])
y = set([])
f = {}
while True:
	for i in x:
		u = s[i]
		if i != 1:
			u.remove(f[i])
		if len(u) == 0:
			leaf += [i]
		elif d[i] == m:
			for j in u:
				f[j] = i
				d[j] = m
		else:
			for j in u:
				f[j] = i
				d[j] = 0 if cat[j - 1] == 0 else d[i] + 1
		y |= u
	if y == set([]):
		break
	else:
		x = copy.copy(y)
		y = set([])
k = 0
for i in leaf:
	if d[i] != m:
		k += 1
print(k)


import queue

def bfs_count_possible_leaves(n, m, a, graph):
	consecutive_cats = [-1 for i in range(n + 9)]
	total_restaurants = 0
	consecutive_cats[1] = a[0]
	q = queue.Queue()
	q.put(1)
	while not q.empty():
		u = q.get()
		if len(graph[u]) == 1 and u != 1:
			total_restaurants += 1
		else:
			for v in graph[u]:
				if consecutive_cats[v] == -1:
					if a[v - 1] == 0:
						consecutive_cats[v] = 0
					else:
						consecutive_cats[v] = consecutive_cats[u] + 1
					if consecutive_cats[v] <= m:
						q.put(v)
	return total_restaurants

def solution():
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	graph = [[] for i in range(n + 1)]
	root = -1
	for i in range(1, n):
		(s, e) = map(int, input().split())
		graph[s].append(e)
		graph[e].append(s)
	print(bfs_count_possible_leaves(n, m, a, graph))
solution()


(n, m) = list(map(int, input().split()))
a = list(map(int, input().split()))
t = n - 1
edges = {}
while t > 0:
	edg = list(map(int, input().split()))
	for i in [0, 1]:
		if edg[i] in edges:
			edges[edg[i]].append(edg[1 - i])
		else:
			edges[edg[i]] = [edg[1 - i]]
	t -= 1

def dfs():
	(stack, marked, counts) = ([], [False] * n, [0] * n)
	cnt = 0
	stack.append(1)
	if a[0] == 1:
		counts[0] = 1
	while len(stack) > 0:
		v = stack.pop()
		if not marked[v - 1]:
			marked[v - 1] = True
			if len(edges[v]) <= 1 and v != 1:
				cnt += 1
			else:
				for w in edges[v]:
					if a[w - 1] == 1:
						if a[v - 1] == 1:
							counts[w - 1] = counts[v - 1] + 1
						else:
							counts[w - 1] = 1
					if counts[w - 1] > m:
						continue
					stack.append(w)
	return cnt
print(dfs())


import sys
readline = sys.stdin.readline

def i1():
	return int(readline())

def nl():
	return [int(s) for s in readline().split()]

def nn(n):
	return [int(readline()) for i in range(n)]

def nnp(n, x):
	return [int(readline()) + x for i in range(n)]

def nmp(n, x):
	return (int(readline()) + x for i in range(n))

def nlp(x):
	return [int(s) + x for s in readline().split()]

def nll(n):
	return [[int(s) for s in readline().split()] for i in range(n)]

def mll(n):
	return ([int(s) for s in readline().split()] for i in range(n))

def s1():
	return readline().rstrip()

def sl():
	return [s for s in readline().split()]

def sn(n):
	return [readline().rstrip() for i in range(n)]

def sm(n):
	return (readline().rstrip() for i in range(n))

def redir(s):
	global readline
	import os
	fn = sys.argv[0] + f'/../in-{s}.txt'
	readline = open(fn).readline if os.path.exists(fn) else readline
import os
if 'DEPTH' in os.environ:

	def printd(*a, **aa):
		print(*a, **aa)
else:

	def printd(*a, **aa):
		pass
redir('c')
(n, m) = nl()
cats = [0] + nl()
nodes = [[] for i in range(n + 1)]
notseen = [True] * (n + 1)
for i in range(1, n):
	(u, v) = nl()
	nodes[u].append(v)
	nodes[v].append(u)
stk = [(1, cats[1])]
notseen[1] = False
cnt = 0
_ = 0
printd(n, m)
printd(nodes)
printd(cats)
while stk:
	top = stk.pop()
	(r, ncats) = top
	_ += 1
	printd('-' * min(_, 10), top)
	if len(nodes[r]) == 1 and r > 1:
		cnt += 1
	else:
		flag = cats[r]
		for c in nodes[r]:
			if notseen[c]:
				notseen[c] = False
				ncats_new = ncats + cats[c] if flag else cats[c]
				if ncats_new > m:
					continue
				stk.append((c, ncats_new))
print(cnt)


class Node:

	def __init__(self, value, children, isCat):
		self.value = value
		self.children = children
		self.isCat = isCat
(n, m) = map(int, input().split())
cats_list = [int(i) for i in input().split()]
set_of_edges = []
for i in range(n):
	set_of_edges.append([])
for i in range(n - 1):
	(a, b) = map(int, input().split())
	set_of_edges[a - 1].append([a, b])
	set_of_edges[b - 1].append([b, a])
cat_sign = True if cats_list[0] == 1 else False
tree = Node(1, {}, cat_sign)
parents_children = [[1, 0, tree]]
parents_children_1 = []
while parents_children != []:
	for triple in parents_children:
		parent = triple[1]
		node = triple[0]
		TREE = triple[2]
		for pair in set_of_edges[node - 1]:
			if pair == [node, parent]:
				continue
			child = pair[1]
			sign = True if cats_list[child - 1] == 1 else False
			TREE.children[child] = Node(child, {}, sign)
			parents_children_1.append([child, node, TREE.children[child]])
	parents_children = parents_children_1
	parents_children_1 = []
ans = 0
test_cases = [[tree, 0]]
test_cases_1 = []
while test_cases != []:
	for t in test_cases:
		TREE = t[0]
		num_cats = t[1] + 1 if TREE.isCat else 0
		if m < num_cats:
			continue
		if TREE.children == {} and num_cats <= m:
			ans += 1
		else:
			for num in TREE.children:
				test_cases_1.append([TREE.children[num], num_cats])
	test_cases = test_cases_1
	test_cases_1 = []
print(ans)


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)


(n, m) = [int(x) for x in input().split()]
cat = [int(x) for x in input().split()]
E = {v: [] for v in range(1, n + 1)}
for i in range(n - 1):
	(u, v) = [int(x) for x in input().split()]
	E[u].append(v)
	E[v].append(u)

def DFS():
	visited = {v: False for v in range(1, n + 1)}
	stack = [(1, cat[0], 0)]
	ans = 0
	while stack:
		(node, last_cats, cats) = stack.pop()
		if visited[node]:
			continue
		visited[node] = True
		if cats <= m and last_cats <= m:
			if len(E[node]) == 1:
				ans += 1
			stack.extend(((v, (last_cats + 1) * cat[v - 1], max(cats, last_cats * (cat[v - 1] ^ 1))) for v in E[node]))
	return ans - (len(E[1]) == 1 and cat[0] <= m)
print(DFS())


(n, m) = [int(i) for i in input().split()]
ind = [int(i) for i in input().split()]
T = [[-1, []] for i in range(n + 1)]
T[1][0] = ind[0]
cnt = 0
for i in range(n - 1):
	(a, b) = [int(i) for i in input().split()]
	T[a][1].append((b, a))
	T[b][1].append((a, b))
stack = T[1][1]
while stack != []:
	(t, prev) = stack.pop()
	if T[t][0] >= 0:
		continue
	T[t][0] = 0 if ind[t - 1] == 0 else T[prev][0] + 1
	if T[t][0] > m:
		continue
	if len(T[t][1]) == 1:
		cnt += 1
		continue
	stack += T[t][1]
print(cnt)


def bfs(n, m, a, tree):
	res = 0
	visited = [False] * n
	path = [-1] * n
	visited[0] = True
	lst = [0]
	path[0] = a[0]
	while len(lst):
		u = lst.pop()
		for i in tree[u]:
			if visited[i] == False:
				visited[i] = True
				if a[i] == 1:
					path[i] = path[u] + a[i]
				else:
					path[i] = 0
				if path[i] > m:
					continue
				else:
					if len(tree[i]) == 1 and i != 0:
						res += 1
					lst.append(i)
	return res
(n, m) = map(int, input().split())
a = list(map(int, input().split()))
tree = [[] for i in range(n)]
for edge in range(n - 1):
	(v1, v2) = map(int, input().strip().split(' '))
	tree[v1 - 1].append(v2 - 1)
	tree[v2 - 1].append(v1 - 1)
print(bfs(n, m, a, tree))


(n, m) = map(int, input().split())
s = [int(i) for i in input().split()]
d = {}
for i in range(n):
	d[i + 1] = []
for i in range(n - 1):
	(a, b) = map(int, input().split())
	d[a].append(b)
	d[b].append(a)
ans = 0
rec = [(1, 0, 1)]
while len(rec) != 0:
	(i, c, last) = rec.pop()
	if s[i - 1]:
		c += 1
	else:
		c = 0
	if c > m:
		continue
	if i != 1 and len(d[i]) == 1:
		ans += 1
		continue
	for k in d[i]:
		if k != last:
			rec.append((k, c, i))
print(ans)


cat = dict()
graph = dict()
visited = set()
queue = [1]
res = 0
(n, m) = map(int, input().split())
a = list(map(int, input().split()))
for _ in range(n - 1):
	(x, y) = map(int, input().split())
	if x not in graph.keys():
		graph[x] = []
	if y not in graph.keys():
		graph[y] = []
	graph[x].append(y)
	graph[y].append(x)
cat[1] = a[0]
while len(queue) > 0:
	x = queue.pop(0)
	visited.add(x)
	if cat[x] > m:
		continue
	b = 0
	for k in graph[x]:
		if k not in visited:
			if a[k - 1] == 1:
				cat[k] = cat[x] + 1
			else:
				cat[k] = 0
			queue.append(k)
			b = 1
	if b == 0:
		res += 1
print(res)


from sys import stdin, setrecursionlimit
import collections

def stack_dfs(visited, node, count):
	stack = [node]
	count = [cats[node - 1]]
	ans = 0
	while len(stack) > 0:
		node = stack.pop()
		c = count.pop()
		visited[node] = True
		if c > m:
			continue
		flag = 0
		for i in graph[node]:
			if visited[i] == False:
				flag = 1
				stack.append(i)
				if cats[i - 1] == 1:
					count.append(1 + c)
				else:
					count.append(0)
		if flag == 0:
			ans += 1
	return ans
(n, m) = list(map(int, stdin.readline().split()))
cats = list(map(int, stdin.readline().split()))
graph = collections.defaultdict(list)
for _ in range(n - 1):
	(u, v) = list(map(int, stdin.readline().split()))
	graph[u].append(v)
	graph[v].append(u)
visited = dict()
for i in range(1, n + 1):
	visited[i] = False
node = 1
print(stack_dfs(visited, node, 0))


import sys, threading
sys.setrecursionlimit(10 ** 6)
threading.stack_size(10 ** 8)

def dfs(x, c):
	global m, v, l1, l, adj
	v[x] = 1
	if c > m:
		l1[x] = 1
	for i in adj[x]:
		if not v[i]:
			if l1[x] == 1:
				dfs(i, m + 1)
			elif l[i - 1] == 1:
				dfs(i, c + 1)
			else:
				dfs(i, 0)

def main():
	global m, v, l1, l, adj
	(n, m) = map(int, input().split())
	l = list(map(int, input().split()))
	v = [0] * (n + 1)
	l1 = [0] * (n + 1)
	adj = [[] for i in range(n + 1)]
	for i in range(n - 1):
		(x, y) = map(int, input().split())
		adj[x].append(y)
		adj[y].append(x)
	dfs(1, l[0])
	ans = 0
	for i in range(2, n + 1):
		if len(adj[i]) == 1:
			if l1[i] == 0:
				ans += 1
	print(ans)
t = threading.Thread(target=main)
t.start()
t.join()


from collections import defaultdict

def solve(cats, edges, n, m):
	connected = defaultdict(set)
	for (a, b) in edges:
		connected[a].add(b)
		connected[b].add(a)

	def connected_to(v, visited):
		return connected[v] - visited
	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
[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)


import queue
(n, m) = map(int, input().split())
graph = [[] for i in range(n + 1)]
visited = [0 for i in range(n + 1)]
path = [0 for i in range(n + 1)]
restaurant = []
countCat = [0 for i in range(n + 1)]
cat = list(map(int, input().split()))
for i in range(1, n):
	(x, y) = map(int, input().split())
	graph[x].append(y)
	graph[y].append(x)

def BFS(s):
	q = queue.Queue()
	visited[s] = True
	q.put(s)
	while not q.empty():
		u = q.get()
		for v in graph[u]:
			if visited[v] == 0:
				visited[v] = 1
				q.put(v)
				path[v] = u

def AvoidCat(s):
	p = queue.Queue()
	p.put(s)
	temp = m
	count = 0
	if cat[0] == 1:
		path[1] = 1
		countCat[1] = 1
	while not p.empty():
		u = p.get()
		if u > 1 and cat[u - 1] == 1 and (cat[path[u] - 1] == 1):
			countCat[u] = countCat[path[u]] + 1
		elif cat[u - 1] == 0:
			countCat[u] = 0
		else:
			countCat[u] = 1
		if countCat[u] > m:
			continue
		if len(graph[u]) == 1 and u != 1:
			count += 1
		for v in graph[u]:
			if visited[v] == 1:
				visited[v] = 2
				p.put(v)
	return count
BFS(1)
print(AvoidCat(1))


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)


from queue import Queue
s = list(map(int, input().split()))
(vertices, cats) = (s[0], s[1])
is_cat = list(map(int, input().split()))
visited = [False for i in range(vertices)]
g = [[] for i in range(vertices)]
for i in range(vertices - 1):
	s = list(map(int, input().split()))
	g[s[0] - 1].append(s[1] - 1)
	g[s[1] - 1].append(s[0] - 1)
restaurants = 0
q = Queue()
if cats != 0 or (cats == 0 and is_cat[0] == False):
	for i in g[0]:
		q.put((i, is_cat[0], 0))
while not q.empty():
	(vertice, cat, come) = q.get()
	if is_cat[vertice]:
		cat += 1
	else:
		cat = 0
	if cat > cats:
		continue
	if len(g[vertice]) == 1:
		restaurants += 1
		continue
	for i in g[vertice]:
		if i != come:
			q.put((i, cat, vertice))
print(restaurants)


(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())
A = {v: a for (v, a) in enumerate(map(int, input().split()), 1)}
G = {v: set() for v in range(1, n + 1)}
for _ in range(n - 1):
	(v1, v2) = map(int, input().split())
	G[v1].add(v2)
	G[v2].add(v1)
paths = 0
(stack, visited) = ([(1, A[1])], set())
while stack:
	(v, counter) = stack.pop()
	visited.add(v)
	children = G[v] - visited
	if children:
		for v in children:
			new_counter = counter + 1 if A[v] else 0
			if new_counter <= m:
				stack.append((v, new_counter))
	else:
		paths += 1
print(paths)


(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 bfs(i):
	visited.add(i)
	for x in neighbor[i]:
		if x not in visited:
			if cats[x - 1]:
				consecutive[x - 1] = consecutive[i - 1] + 1
			else:
				consecutive[x - 1] = 0
			if consecutive[x - 1] <= m:
				queue.append(x)
(n, m) = map(int, input().split())
cats = [int(x) for x in input().split()]
visited = set({})
consecutive = [0 for x in range(n)]
consecutive[0] = cats[0]
neighbor = {}
queue = [1]
for i in range(n - 1):
	(a, b) = map(int, input().split())
	if a not in neighbor:
		neighbor[a] = [b]
	else:
		neighbor[a].append(b)
	if b not in neighbor:
		neighbor[b] = [a]
	else:
		neighbor[b].append(a)
while len(queue) != 0:
	cur = queue.pop(0)
	bfs(cur)
ans = 0
for i in range(2, n + 1):
	if len(neighbor[i]) == 1 and i in visited:
		ans += 1
print(ans)


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)


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
f = [0] * (n + 1)
b = [[] for i in range(n + 1)]
for i in range(n - 1):
	(x, y) = map(int, input().split())
	x -= 1
	y -= 1
	b[x].append(y)
	b[y].append(x)
c = []
d = []
e = []
c.append(a[0])
d.append(0)
e.append(a[0])
f[0] = 1
ret = 0
while len(c) > 0:
	v = d.pop()
	mm = e.pop()
	cur = c.pop()
	for u in b[v]:
		if f[u] == 0:
			f[u] = 1
			d.append(u)
			tmp = (cur + 1) * a[u]
			c.append(tmp)
			e.append(max(mm, tmp))
	if v != 0 and len(b[v]) == 1:
		if mm <= m:
			ret += 1
print(ret)


def bfs(G, s, max_cats, are_cats):
	from queue import Queue
	n = len(G)
	Q = Queue()
	visited = [False for _ in range(n)]
	visited[s] = True
	counter = 0
	Q.put((s, 0))
	while not Q.empty():
		(u, cats) = Q.get()
		if are_cats[u]:
			cats += 1
		else:
			cats = 0
		if cats > max_cats:
			continue
		leaf = True
		for v in G[u]:
			if not visited[v]:
				leaf = False
				visited[v] = True
				Q.put((v, cats))
		if leaf:
			counter += 1
	return counter
(number_of_vertices, max_cats) = map(int, input().split())
are_cats = list(map(int, input().split()))
G = [[] for _ in range(number_of_vertices)]
for _ in range(number_of_vertices - 1):
	(v, u) = map(int, input().split())
	v -= 1
	u -= 1
	G[v].append(u)
	G[u].append(v)
result = bfs(G, 0, max_cats, are_cats)
print(result)


import queue
MAX = 10 ** 5 + 1
graph = [[] for i in range(MAX)]
visited = [False] * MAX
dist = [0] * MAX
(V, max_continuity_cats) = list(map(int, input().split()))
cats_position = list(map(int, input().split()))
for i in range(V - 1):
	(u, v) = list(map(int, input().split()))
	graph[u].append(v)
	graph[v].append(u)
start = 1
q = queue.Queue()
q.put(start)
visited[start] = True
dist[start] = 1 if cats_position[start - 1] else 0
result = 0
while not q.empty():
	u = q.get()
	for v in graph[u]:
		if not visited[v]:
			q.put(v)
			visited[v] = True
			dist[v] = dist[u] + 1 if cats_position[v - 1] else 0
			if dist[v] > max_continuity_cats:
				graph[v] = []
			elif len(graph[v]) == 1:
				result += 1
print(result)


(n, m) = [int(i) for i in input().split()]
a = [0] + [int(i) for i in input().split()]
grph = {}
for i in range(1, n + 1):
	grph[i] = set()
for i in range(n - 1):
	(x, y) = [int(j) for j in input().split()]
	grph[x].add(y)
	grph[y].add(x)
to_visit = [1]
visited = [False] * (n + 1)
billi = [[0, 0]] * (n + 1)
billi[1] = [a[1], a[1]]
leafs = []
array = [0] * (n + 1)
num = 0
while to_visit:
	v = to_visit.pop(0)
	visited[v] = True
	for n in grph[v]:
		if not visited[n]:
			to_visit.append(n)
			pos_max = 0
			if a[v] == 0:
				pos_max = a[n]
			else:
				pos_max = billi[v][0] + a[n]
			if billi[v][1] < pos_max:
				billi[n] = [pos_max, pos_max]
			else:
				billi[n] = [pos_max, billi[v][1]]
			array[v] += 1
	if array[v] == 0 and billi[v][1] <= m:
		num += 1
print(num)


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)


import sys
import time

def input():
	return sys.stdin.readline().strip()

def iinput():
	return int(input())

def rinput():
	return map(int, sys.stdin.readline().strip().split())

def get_list():
	return list(map(int, sys.stdin.readline().strip().split()))
mod = int(1000000000.0) + 7
(n, m) = rinput()
a = get_list()
g = [[] for _ in range(n)]
v = [0] * n
for _ in range(n - 1):
	(x, y) = rinput()
	g[x - 1].append(y - 1)
	g[y - 1].append(x - 1)
ans = i = 0
q = [(0, 0)]
while i < len(q):
	(x, N) = q[i]
	v[x] = 1
	if a[x] + N <= m:
		L = 1
		for y in g[x]:
			if not v[y]:
				L = 0
				q.append((y, a[x] * (a[x] + N)))
		if L:
			ans += 1
	i += 1
print(ans)


from sys import stdin, stdout
input = stdin.buffer.readline
import collections

def main():
	(n, m) = map(int, input().split())
	cats = list(map(int, input().split()))
	tree = collections.defaultdict(list)
	for _ in range(n - 1):
		(u, v) = map(int, input().split())
		u -= 1
		v -= 1
		tree[u].append(v)
		tree[v].append(u)
	res = 0
	queue = collections.deque()
	queue.append([0, -1, 0])
	while queue:
		(u, p, count) = queue.popleft()
		isleaf = True
		total = 0 if cats[u] == 0 else count + 1
		if total <= m:
			for v in tree[u]:
				if v != p:
					isleaf = False
					queue.append([v, u, total])
			if isleaf:
				res += 1
	print(res)
main()


def main():
	(n, k) = map(int, input().split())
	mat = list(map(int, input().split()))
	subs = list((set() for i in range(n)))
	points = [0] * (n + 1)
	points[0] = mat[0]
	for i in range(n - 1):
		(a, b) = map(int, input().split())
		a -= 1
		b -= 1
		subs[a].add(b)
		subs[b].add(a)
	steps = [0]
	result = 0
	while len(steps) > 0:
		s = steps.pop()
		if len(subs[s]) == 0:
			if points[s] <= k:
				result += 1
		for i in subs[s]:
			subs[i].remove(s)
			if mat[i] == 0 and points[s] <= k:
				points[i] = 0
			else:
				points[i] = points[s] + 1
			steps.append(i)
	print(result)
main()


from sys import *
from collections import deque
setrecursionlimit(200000)
N = 10 ** 5 + 5
(cats, visited) = ([0] * N, [0] * N)
adj = [[] for j in range(N)]

def solve():
	(n, m) = map(int, input().split())
	(l, ans, dq, cat) = ([int(i) for i in input().split()], 0, deque(), 0)
	for i in range(n):
		cats[i] = l[i]
	for i in range(n - 1):
		(a, b) = map(int, input().split())
		(a, b) = (a - 1, b - 1)
		adj[a].append(b)
		adj[b].append(a)
	dq.append((0, cats[0]))
	while len(dq) > 0:
		(node, child) = dq.pop()
		visited[node] = 1
		if node != 0 and len(adj[node]) == 1:
			if child <= m:
				ans = ans + 1
		if cats[node] == 0 and child <= m:
			child = 0
		for next in adj[node]:
			if visited[next] == 0:
				dq.append((next, cats[next] + child))
	print(ans)
solve()


(n, k) = map(int, input().split())
cats = list(map(int, input().split()))
adj = [[] for i in range(n + 1)]
for i in range(n - 1):
	(x, y) = map(int, input().split())
	adj[x].append(y)
	adj[y].append(x)
top = bot = 0
q = [1]
INF = int(1000000000.0)
visited = [INF] * (n + 1)
con = [0] * (n + 1)
visited[1] = cats[0]
while bot <= top:
	u = q[bot]
	bot += 1
	if visited[u] > k:
		continue
	for v in adj[u]:
		if visited[v] == INF:
			if cats[v - 1] == 0:
				visited[v] = 0
			else:
				visited[v] = visited[u] + cats[v - 1]
			con[u] += 1
			top += 1
			q.append(v)
res = 0
for i in range(2, n + 1):
	if con[i] == 0 and visited[i] <= k:
		res += 1
print(res)


from collections import defaultdict
from sys import setrecursionlimit
import threading

def solve(current, parent, cats):
	global out
	if cats > m:
		return 0
	leaf = 1
	for adj in e[current]:
		if adj != parent:
			leaf = 0
			solve(adj, current, cats * a[adj] + a[adj])
	out += leaf

def read_input():
	global n, m, a, e
	(n, m) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	e = defaultdict(list)
	for _ in range(n - 1):
		(u, v) = list(map(int, input().split()))
		u -= 1
		v -= 1
		e[u].append(v)
		e[v].append(u)

def main():
	global n, m, a, e, out
	out = 0
	read_input()
	solve(0, -1, a[0])
	print(out)
threading.stack_size(10 ** 8)
setrecursionlimit(10 ** 5 + 100)
threading.Thread(target=main).start()


from sys import *
from collections import deque
setrecursionlimit(20000)
N = 10 ** 5 + 5
(cats, visited) = ([0] * N, [0] * N)
adj = [[] for j in range(N)]

def main():
	(n, m) = map(int, input().split())
	(l, ans, dq, cat) = ([int(i) for i in input().split()], 0, deque(), 0)
	for i in range(n):
		cats[i] = l[i]
	for i in range(n - 1):
		(a, b) = map(int, input().split())
		(a, b) = (a - 1, b - 1)
		adj[a].append(b)
		adj[b].append(a)
	dq.append((0, cats[0]))
	while len(dq) > 0:
		(now, nc) = dq.pop()
		visited[now] = 1
		if now != 0 and len(adj[now]) == 1:
			if nc <= m:
				ans += 1
		if cats[now] == 0 and nc <= m:
			nc = 0
		for i in adj[now]:
			if visited[i] == 0:
				dq.append((i, cats[i] + nc))
	print(ans)
main()


from collections import deque
visited = []
num_cat_consecutive = []
max_num_cat_consecutive = []
cat_on_vertex = []
adj_list = []
num_of_leaf_reachable = []
edge_id = []
S = deque()
m = 0

def DFS(u, number_highest_cat_consecutive):
	S.append((u, number_highest_cat_consecutive))
	while S:
		(u, number_highest_cat_consecutive) = S.pop()
		visited[u] = 1
		k = len(adj_list[u])
		if k == 1:
			if number_highest_cat_consecutive <= m and visited[adj_list[u][0]] == 1 and (u != 1):
				num_of_leaf_reachable[0] += 1
				continue
		while edge_id[u] < k:
			f = adj_list[u][edge_id[u]]
			edge_id[u] += 1
			if visited[f] == 1:
				continue
			S.append((u, number_highest_cat_consecutive))
			if cat_on_vertex[f] == 1:
				num_cat_consecutive[f] = num_cat_consecutive[u] + 1
				number_highest_cat_consecutive = max(num_cat_consecutive[f], max_num_cat_consecutive[u])
				max_num_cat_consecutive[f] = number_highest_cat_consecutive
			elif cat_on_vertex[f] == 0:
				num_cat_consecutive[f] = 0
				max_num_cat_consecutive[f] = max_num_cat_consecutive[u]
				number_highest_cat_consecutive = max_num_cat_consecutive[f]
			visited[f] = 1
			S.append((f, number_highest_cat_consecutive))
			break
l = input().split()
n = int(l[0])
m = int(l[1])
l = input().split()
cat_on_vertex.append(0)
num_cat_consecutive.append(0)
adj_list.append([])
visited.append(0)
max_num_cat_consecutive.append(0)
num_of_leaf_reachable.append(0)
edge_id.append(0)
for i in range(n):
	cat_on_vertex.append(int(l[i]))
	num_cat_consecutive.append(0)
	visited.append(0)
	adj_list.append([])
	max_num_cat_consecutive.append(0)
	edge_id.append(0)
for i in range(n - 1):
	l = input().split()
	adj_list[int(l[0])].append(int(l[1]))
	adj_list[int(l[1])].append(int(l[0]))
num_cat_consecutive[1] = cat_on_vertex[1]
max_num_cat_consecutive[1] = cat_on_vertex[1]
DFS(1, cat_on_vertex[1])
print(num_of_leaf_reachable[0])


(n, m) = map(int, input().split())
arr = list(map(int, input().split()))
adj = [[] for i in range(n)]
cats = [0 for _ in range(n)]
for i in range(n - 1):
	(x, y) = map(int, input().split())
	adj[x - 1].append(y - 1)
	adj[y - 1].append(x - 1)
d = [0]
cats[0] = arr[0]
k = 0
while d != []:
	t = d.pop(0)
	if adj[t] == []:
		if cats[t] <= m:
			k += 1
	for i in adj[t]:
		adj[i].remove(t)
		if arr[i] == 0 and cats[t] <= m:
			cats[i] = 0
		else:
			cats[i] = cats[t] + 1
		d.append(i)
print(k)


def go_child(node, path_cat, parent):
	m_cat = 0
	if cat[node] == 0:
		m_cat = 0
	else:
		m_cat = path_cat + cat[node]
	if m_cat > m:
		return 0
	isLeaf = True
	sums = 0
	for j in e[node]:
		if j == parent:
			continue
		isLeaf = False
		sums += go_child(j, m_cat, node)
	if isLeaf:
		return 1
	return sums

def go_bfs():
	bfs = [(cat[0], 0, 0)]
	sums = 0
	while bfs:
		isLeaf = True
		(level_cat, v, p) = bfs.pop()
		for j in e[v]:
			if j == p:
				continue
			isLeaf = False
			if cat[j] == 0:
				bfs.append((0, j, v))
			elif level_cat + 1 <= m:
				bfs.append((level_cat + 1, j, v))
		if isLeaf:
			sums += 1
	return sums
(n, m) = map(int, input().split())
cat = list(map(int, input().split()))
e = [[] for i in range(n)]
for i in range(n - 1):
	(v1, v2) = map(int, input().split())
	e[v1 - 1].append(v2 - 1)
	e[v2 - 1].append(v1 - 1)
print(go_bfs())


import sys
input = sys.stdin.readline
from collections import deque

class Graph(object):

	def __init__(self, n, d):
		self.n = n
		self.graph = [[] for i in range(n)]
		self.parent = [-1 for i in range(n)]
		self.directed = d

	def addEdge(self, x, y):
		self.graph[x].append(y)
		if not self.directed:
			self.graph[y].append(x)

	def bfs(self, root):
		queue = [root]
		queue = deque(queue)
		vis = [0] * self.n
		while len(queue) != 0:
			element = queue.popleft()
			vis[element] = 1
			flag = 0
			for i in self.graph[element]:
				if vis[i] == 0:
					flag = 1
					if cats[element] == -1:
						cats[i] = -1
					elif a[i] == 1:
						cats[i] = cats[element] + 1
						if cats[i] == m + 1:
							cats[i] = -1
					else:
						cats[i] = 0
					queue.append(i)
					self.parent[i] = element
					vis[i] = 1
			if not flag:
				leaf.append(element)

	def dfs(self, root, ans):
		stack = [root]
		vis = [0] * self.n
		stack2 = []
		while len(stack) != 0:
			element = stack.pop()
			if vis[element]:
				continue
			vis[element] = 1
			stack2.append(element)
			for i in self.graph[element]:
				if vis[i] == 0:
					self.parent[i] = element
					stack.append(i)
		while len(stack2) != 0:
			element = stack2.pop()
			m = 0
			for i in self.graph[element]:
				if i != self.parent[element]:
					m += ans[i]
			ans[element] = m
		return ans

	def shortestpath(self, source, dest):
		self.bfs(source)
		path = [dest]
		while self.parent[path[-1]] != -1:
			path.append(parent[path[-1]])
		return path[::-1]

	def ifcycle(self):
		self.bfs(0)
		queue = [0]
		vis = [0] * n
		queue = deque(queue)
		while len(queue) != 0:
			element = queue.popleft()
			vis[element] = 1
			for i in graph[element]:
				if vis[i] == 1 and i != parent[element]:
					return True
				if vis[i] == 0:
					queue.append(i)
					vis[i] = 1
		return False

	def reroot(self, root, ans):
		stack = [root]
		vis = [0] * n
		while len(stack) != 0:
			e = stack[-1]
			if vis[e]:
				stack.pop()
				continue
			vis[e] = 1
			for i in graph[e]:
				if not vis[e]:
					stack.append(i)
			if self.parent[e] == -1:
				continue
(n, m) = map(int, input().split())
a = list(map(int, input().split()))
g = Graph(n, False)
for i in range(n - 1):
	(x, y) = map(int, input().split())
	g.addEdge(x - 1, y - 1)
cats = [0] * n
leaf = []
if a[0] == 1:
	cats[0] = 1
g.bfs(0)
ans = 0
for i in leaf:
	if cats[i] != -1:
		ans += 1
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()


import unittest
import sys
import collections

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:

	def __init__(self, test_inputs=None):
		it = iter(test_inputs.split('\n')) if test_inputs else None

		def uinput():
			return next(it) if it else sys.stdin.readline().rstrip()
		[self.n, self.m] = list(map(int, uinput().split()))
		self.nums = list(map(int, uinput().split()))
		(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
		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):
		result = 0
		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)
		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)

class unitTests(unittest.TestCase):

	def test_single_test(self):
		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])
		self.assertEqual(Park(test).calculate(), '2')
		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')
		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')
		test = ''

	def time_limit_test(self, nmax):
		import random
		import timeit
		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'
		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():
	sys.setrecursionlimit(100000)
	if sys.argv[-1] == '-ut':
		unittest.main(argv=[' '])
	sys.stdout.write(Park().calculate())
__starting_point()


def DFS(tree, cat, pos, prev, isCat, m, count, travel, visit):
	while len(travel) > 0:
		if int(isCat[pos]) and cat[pos] == 0:
			cat[pos] += int(isCat[pos]) + cat[prev]
		elif not int(isCat[pos]):
			cat[pos] = 0
		if cat[pos] <= m:
			if len(tree[pos]) == 1 and pos != 0 and (visit[pos] == 0):
				count += 1
				travel.pop()
				visit[pos] = 1
				prev = pos
				pos = travel[len(travel) - 1]
			else:
				index = 0
				if len(tree[pos]) > 0:
					if tree[pos][index] == prev:
						tree[pos].pop(0)
				if len(tree[pos]) > 0:
					travel += [tree[pos][index]]
					visit[pos] = 1
					prev = pos
					pos = travel[len(travel) - 1]
				else:
					travel.pop()
					if len(travel) > 0:
						prev = pos
						pos = travel[len(travel) - 1]
		else:
			travel.pop()
			if len(travel) > 0:
				prev = pos
				pos = travel[len(travel) - 1]
	return count
line = input().split()
n = int(line[0])
m = int(line[1])
tree = []
for i in range(n):
	tree.append([])
visit = [0] * n
isCat = input().split()
count = 0
travel = [0]
cat = [0] * n
for i in range(n - 1):
	xy = input().split()
	tree[int(xy[0]) - 1].append(int(xy[1]) - 1)
	tree[int(xy[1]) - 1].append(int(xy[0]) - 1)
count = DFS(tree, cat, 0, 0, isCat, m, count, travel, visit)
print(count)


def line():
	return [int(s) for s in input().split()]
(n, m) = line()
haveCat = [0] + line()
edges = {}
for i in range(1, n + 1):
	edges[i] = []
for _ in range(n - 1):
	(x, y) = line()
	edges[x].append(y)
	edges[y].append(x)
went = [False] * (n + 1)
catSeq = [0] * (n + 1)
if haveCat[1]:
	catSeq[1] = 1
target = 0
from collections import deque
Q = deque()
Q.append(1)
while Q:
	x = Q.popleft()
	went[x] = True
	if len(edges[x]) == 1 and x != 1:
		target += 1
		continue
	for y in edges[x]:
		if not went[y]:
			if haveCat[y]:
				catSeq[y] = catSeq[x] + 1
			if catSeq[y] <= m:
				Q.append(y)
print(target)


from collections import defaultdict

def dfs(n, m, a, e):
	s = [(0, 0, 0)]
	v = [True] + [False for _ in range(n)]
	total = 0
	while s:
		(cur, cats, parent) = s[-1]
		cats += 1 if a[cur] else -cats
		if cats > m:
			s.pop()
			cats -= 1
			continue
		added = False
		leaf = len(e[cur]) == 1 and e[cur][0] == parent
		if leaf:
			total += 1
		for j in e[cur]:
			if not v[j]:
				s.append((j, cats, cur))
				added = True
				v[j] = True
		if not added:
			s.pop()
	return total

def solve(n, m, a, e):
	return dfs(n, m, a, e)

def main():
	(n, m) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	e = defaultdict(list)
	for _ in range(n - 1):
		(u, v) = list(map(int, input().split()))
		e[u - 1].append(v - 1)
		e[v - 1].append(u - 1)
	print(solve(n, m, a, e))
main()


from collections import defaultdict

class graph:

	def __init__(self, v):
		self.graph = defaultdict(list)
		self.v = v
		self.cats = []
		self.ref = [0] * v

	def addedge(self, u, v):
		self.graph[u].append(v)
		self.graph[v].append(u)

	def bfs(self, m):
		visited = [False] * self.v
		queue = []
		queue.append(1)
		count = 0
		visited[0] = True
		if self.cats[0] == 1:
			self.ref[0] = 1
		while queue:
			s = queue.pop(0)
			if len(self.graph[s]) == 1 and s != 1:
				count += 1
			for i in self.graph[s]:
				if visited[i - 1] == False:
					visited[i - 1] = True
					if self.ref[s - 1] < m:
						if self.cats[i - 1] == 1:
							self.ref[i - 1] = self.ref[s - 1] + 1
						queue.append(i)
					elif self.ref[s - 1] == m and self.cats[i - 1] == 0:
						queue.append(i)
		return count
[n, m] = [int(x) for x in input().split()]
g = graph(n)
g.cats = [int(x) for x in input().split()]
for i in range(n - 1):
	[a, b] = [int(x) for x in input().split()]
	g.addedge(a, b)
print(g.bfs(m))


def dfs():
	(ans, f) = (0, -1)
	while stk:
		(x, c) = stk.pop()
		vis[x] = 0
		if a[x - 1] == 1:
			vis[x] = c + 1
		if vis[x] <= m:
			f = -1
			for v in g[x]:
				if vis[v] == -1:
					stk.append((v, vis[x]))
					f = 0
			if f == -1:
				ans += 1
	return ans
(n, m) = map(int, input().split())
a = list(map(int, input().split()))
g = [[] for i in range(n + 1)]
for i in range(n - 1):
	(x, y) = map(int, input().split())
	g[x].append(y)
	g[y].append(x)
vis = [-1] * (n + 1)
stk = [(1, 0)]
print(dfs())


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from collections import Counter
import heapq
from collections import Counter

def dfs():
	(ans, f) = (0, -1)
	while q:
		(x, ca) = q.pop()
		vis[x] = 0
		if cat[x] == 1:
			vis[x] = ca + 1
		if vis[x] <= k:
			f = -1
			for j in g[x]:
				if vis[j] == -1:
					q.append((j, vis[x]))
					f = 0
			if f == -1:
				ans += 1
	return ans
q = [(0, 0)]
(n, k) = map(int, input().split())
cat = list(map(int, input().split()))
g = [[] for i in range(n)]
vis = [-1] * n
for i in range(n - 1):
	(u, v) = map(int, input().split())
	g[u - 1].append(v - 1)
	g[v - 1].append(u - 1)
print(dfs())


import sys
input = sys.stdin.buffer.readline
from collections import deque

def prog():
	(n, m) = map(int, input().split())
	cats = list(map(int, input().split()))
	adj_list = [[[], 0] for i in range(n + 1)]
	for i in range(n - 1):
		(a, b) = map(int, input().split())
		adj_list[a][0].append(b)
		adj_list[b][0].append(a)
	consecutive_cats = [0 for i in range(n + 1)]
	consecutive_at_node = [0 for i in range(n + 1)]
	s = deque([0, 1])
	visited = set([0])
	while s:
		curr = s[-1]
		if curr not in visited:
			if cats[curr - 1] == 1:
				consecutive_at_node[curr] = consecutive_at_node[s[-2]] + 1
				consecutive_cats[curr] = max(consecutive_cats[s[-2]], consecutive_at_node[curr])
			else:
				consecutive_at_node[curr] = 0
				consecutive_cats[curr] = consecutive_cats[s[-2]]
			visited.add(curr)
		had_neighbor = False
		for i in range(adj_list[curr][1], len(adj_list[curr][0])):
			neighbor = adj_list[curr][0][i]
			if neighbor not in visited:
				had_neighbor = True
				s.append(neighbor)
				adj_list[curr][1] = i + 1
				break
		if not had_neighbor:
			s.pop()
	visitable_restaurants = 0
	for node in range(2, n + 1):
		if len(adj_list[node][0]) == 1 and consecutive_cats[node] <= m:
			visitable_restaurants += 1
	print(visitable_restaurants)
prog()


import sys

def solve(n, m, cats, edges):
	graph = [[] for _ in range(n)]
	for (x, y) in edges:
		graph[x - 1].append(y - 1)
		graph[y - 1].append(x - 1)
	res = 0
	queue = [(0, 0, -1)]
	while queue:
		(idx, cur_cats, parent) = queue.pop()
		cur_cats = 0 if cats[idx] == 0 else cur_cats + 1
		if cur_cats <= m:
			is_leaf = True
			for to in graph[idx]:
				if to != parent:
					is_leaf = False
					queue.append((to, cur_cats, idx))
			if is_leaf:
				res += 1
	return res

def read(line):
	return [int(c) for c in line.strip().split()]

def main():
	test = sys.stdin.readlines()
	(n, m) = read(test[0])
	cats = read(test[1])
	edges = [read(test[i]) for i in range(2, len(test))]
	ans = solve(n, m, cats, edges)
	print(ans)
main()


from queue import Queue
import sys
sys.setrecursionlimit(1000000)

def BFS(s, a):
	(visited, cnt_cat) = ([], [])
	for i in range(n):
		visited.append(False)
		cnt_cat.append(a[i])
	ans = 0
	q = Queue()
	visited[s] = True
	q.put(s)
	while not q.empty():
		u = q.get()
		for v in graph[u]:
			if not visited[v]:
				visited[v] = True
				if a[u] == 1:
					cnt_cat[v] = cnt_cat[u] + a[v]
				else:
					cnt_cat[v] = a[v]
				if cnt_cat[v] <= m:
					q.put(v)
					if len(graph[v]) == 1:
						ans += 1
	return ans
(n, m) = map(int, input().split())
a = list(map(int, input().split()))
graph = [[] for i in range(n)]
for i in range(n - 1):
	(u, v) = map(int, input().split())
	u -= 1
	v -= 1
	graph[u].append(v)
	graph[v].append(u)
s = 0
print(BFS(s, a))


(n, m) = [int(x) for x in input().split()]
cat = [int(x) for x in input().split()]
t = [[] for _ in range(n)]
v = [0 for _ in range(n)]
for _ in range(1, n):
	(s, e) = [int(x) for x in input().split()]
	t[s - 1].append(e - 1)
	t[e - 1].append(s - 1)
ans = 0
q = [(0, 0)]
l = 0
while l < len(q):
	(x, p) = q[l]
	v[x] = 1
	if cat[x] + p <= m:
		leaf = True
		for y in t[x]:
			if not v[y]:
				leaf = False
				q.append((y, cat[x] * (cat[x] + p)))
		if leaf:
			ans += 1
	l += 1
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()


import sys
from math import *

def minp():
	return sys.stdin.readline().strip()

def mint():
	return int(minp())

def mints():
	return map(int, minp().split())
(n, m) = mints()
a = list(mints())
e = [[] for i in range(n)]
for i in range(n - 1):
	(x, y) = mints()
	e[x - 1].append(y - 1)
	e[y - 1].append(x - 1)
q = [0] * n
ql = 0
qr = 1
q[0] = (0, a[0], a[0])
w = [True] * n
w[0] = False
r = 0
while ql < qr:
	(x, y, yy) = q[ql]
	ql += 1
	for v in e[x]:
		if w[v]:
			z = y + 1 if a[v] > 0 else 0
			q[qr] = (v, z, max(yy, z))
			qr += 1
			w[v] = False
	if x != 0 and len(e[x]) == 1 and (yy <= m):
		r += 1
print(r)


def intline():
	return [int(s) for s in input().split()]
(n, m) = intline()
a = [0] + intline()
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)
seen = [False] * (n + 1)
work = [(1, 0)]
paths = 0
while work:
	(cur, run) = work.pop()
	if seen[cur]:
		continue
	seen[cur] = True
	if a[cur]:
		run += 1
	else:
		run = 0
	if run > m:
		continue
	if len(tree[cur]) == 1 and cur != 1:
		paths += 1
		continue
	for neighbour in tree[cur]:
		work.append([neighbour, run])
print(paths)


import collections
(n, k) = map(int, input().split())
(a, d, l, v) = (list(map(int, input().split())), collections.defaultdict(list), [0] * (n + 1), {})
for i in range(n):
	v[i + 1] = a[i]
for i in range(n - 1):
	(a, b) = map(int, input().split())
	d[a].append(b)
	d[b].append(a)
(q, l[1]) = ([1], 1)
while q:
	s = q.pop()
	for i in d[s]:
		if l[i] == 0:
			q.append(i)
			l[i] = 1
			if v[i] == 0 and v[s] <= k:
				v[i] = 0
			else:
				v[i] += v[s]
ans = 0
for i in d:
	if len(d[i]) == 1 and i != 1:
		if v[i] <= k:
			ans += 1
print(ans)


N = 100001
(d, e) = ([0] * N, [[] for i in range(N)])
(m, n) = (0, 0)
was = [0] * N
cnt = [0] * N
(n, m) = [int(x) for x in input().split()]
d = list(map(int, input().split()))
for i in range(n - 1):
	(u, v) = [int(x) for x in input().split()]
	u -= 1
	v -= 1
	e[u].append(v)
	e[v].append(u)
queue = []
queue.append(0)
was[0] = 1
cnt[0] = d[0]
result = 0
while len(queue) > 0:
	u = queue.pop(0)
	leaf = 1
	for v in e[u]:
		if was[v] == 0:
			leaf = 0
			was[v] = 1
			if cnt[u] + d[v] <= m:
				queue.append(v)
				cnt[v] = cnt[u] * d[v] + d[v]
	result += leaf
print(result)


import sys
input = sys.stdin.readline
(n, m) = map(int, input().split())
d = {}
for i in range(n):
	d[i + 1] = []
a = list(map(int, input().split()))
for i in range(n - 1):
	(x, y) = map(int, input().split())
	d[x].append(y)
	d[y].append(x)
vershina = 1
vs = []
vs.append({'v': vershina, 'c': a[0], 'p': 0})
res = 0
arr = vs.pop()
while vershina > 0:
	isList = True
	for child in d[vershina]:
		if child == arr['p']:
			continue
		isList = False
		cats = a[child - 1] * (arr['c'] + a[child - 1])
		if cats <= m:
			vs.append({'v': child, 'c': cats, 'p': vershina})
	if isList:
		res += 1
	if len(vs) > 0:
		arr = vs.pop()
		vershina = arr['v']
	else:
		vershina = 0
print(res)


(n, m) = [int(i) for i in input().split()]
cats = list(map(int, input().split()))
edges = [[] for i in range(n)]
for _ in range(n - 1):
	(v1, v2) = map(int, input().split())
	edges[v1 - 1].append(v2 - 1)
	edges[v2 - 1].append(v1 - 1)

def bfs():
	bfs = [(cats[0], 0, 0)]
	sums = 0
	while bfs:
		leaf = True
		(cat, v, p) = bfs.pop()
		for j in edges[v]:
			if j == p:
				continue
			leaf = False
			if not cats[j]:
				bfs.append((0, j, v))
			elif cat < m:
				bfs.append((cat + 1, j, v))
		if leaf:
			sums += 1
	return sums
print(bfs())


from collections import defaultdict
import sys
sys.setrecursionlimit(1000001)
(n, maxcats) = map(int, input().split())
cat_in = [False] + [i == '1' for i in input().split()]
g = defaultdict(list)
for _ in range(n - 1):
	(a, b) = map(int, input().split())
	g[a].append(b)
	g[b].append(a)
visited = set()
answ = 0
stack = [(1, 0)]
while stack:
	(node, cats) = stack.pop()
	if node in visited:
		continue
	visited.add(node)
	cats_upto_here = cats + 1 if cat_in[node] else 0
	if cats_upto_here > maxcats:
		continue
	if node != 1 and len(g[node]) == 1:
		answ += 1
	for nxt in g[node]:
		stack.append((nxt, cats_upto_here))
print(answ)


def BFS(q, tree, visit, isCat, cat, m):
	count = 0
	if isCat[0] == '1':
		cat[0] += 1
	while len(q) > 0:
		visited = 0
		for i in tree[q[0]]:
			if visit[i] == 0:
				if isCat[i] == '1':
					cat[i] += cat[q[0]] + 1
				if cat[i] <= m:
					q += [i]
			else:
				visited += 1
		if visited == len(tree[q[0]]):
			count += 1
		visit[q[0]] += 1
		q.pop(0)
	print(count)
line = input().split()
n = int(line[0])
m = int(line[1])
tree = []
for i in range(n):
	tree.append([])
visit = [0] * n
isCat = input().split()
q = [0]
cat = [0] * n
for i in range(n - 1):
	xy = input().split()
	tree[int(xy[0]) - 1].append(int(xy[1]) - 1)
	tree[int(xy[1]) - 1].append(int(xy[0]) - 1)
BFS(q, tree, visit, isCat, cat, m)


inp = lambda : [int(_) for _ in input().split()]
(n, m) = inp()
cat = [0] + inp()
g = [[] for _ in range(n + 1)]
for i in range(n - 1):
	(a, b) = inp()
	g[a].append(b)
	g[b].append(a)
vis = [0] * (n + 1)
ans = i = 0
q = [(1, cat[1])]
while i < len(q):
	(u, pc) = q[i]
	vis[u] = 1
	if pc <= m:
		leaf = 1
		for v in g[u]:
			if not vis[v]:
				leaf = 0
				q.append((v, (pc + 1) * cat[v]))
		if leaf:
			ans += 1
	i += 1
print(ans)


import collections, sys, threading
sys.setrecursionlimit(10 ** 9)
threading.stack_size(10 ** 8)

def solve():

	def go_child(node, path_cat, parent):
		m_cat = 0
		if cat[node] == 0:
			m_cat = 0
		else:
			m_cat = path_cat + cat[node]
		if m_cat > m:
			return 0
		isLeaf = True
		sums = 0
		for j in e[node]:
			if j == parent:
				continue
			isLeaf = False
			sums += go_child(j, m_cat, node)
		if isLeaf:
			return 1
		return sums
	(n, m) = map(int, input().split())
	cat = list(map(int, input().split()))
	e = [[] for i in range(n)]
	for i in range(n - 1):
		(v1, v2) = map(int, input().split())
		e[v1 - 1].append(v2 - 1)
		e[v2 - 1].append(v1 - 1)
	print(go_child(0, 0, -1))
threading.Thread(target=solve).start()


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

def getInt():
	return int(input())

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

def getStr():
	return input()

def listStr():
	return list(input())

def bfs(graph, visited, node, queue, A, M):
	visited[node] = 1
	queue.append(node)
	max_run = dict()
	max_run[node] = A[node]
	curr_run = dict()
	curr_run[node] = A[node]
	ans = 0
	while queue:
		s = queue.pop()
		tmp = 0
		for neighbour in graph[s]:
			if neighbour not in visited:
				tmp += 1
				visited[neighbour] = 1
				queue.append(neighbour)
				if A[neighbour]:
					max_run[neighbour] = max(max_run[s], curr_run[s] + 1)
					curr_run[neighbour] = curr_run[s] + 1
				else:
					max_run[neighbour] = max_run[s]
					curr_run[neighbour] = 0
		if tmp == 0 and max_run[s] <= M:
			ans += 1
	return ans

def solve():
	(N, M) = getInts()
	A = [0] + getInts()
	graph = {}
	parents = {}
	for n in range(N - 1):
		(x, y) = getInts()
		if x not in graph:
			graph[x] = set()
		graph[x].add(y)
		if y not in graph:
			graph[y] = set()
		graph[y].add(x)
	ans = bfs(graph, {}, 1, [], A, M)
	return ans
ans = solve()
print(ans)


def read_ints():
	return [int(s) for s in input().split()]
[n, m] = read_ints()
a = read_ints()
adj = [[] for i in range(n)]
for i in range(n - 1):
	[x, y] = read_ints()
	x -= 1
	y -= 1
	adj[x].append(y)
	adj[y].append(x)
cnt = [-1 for i in range(n)]
cnt[0] = a[0]
res = 0
queue = [0]
head = 0
while len(queue) > head:
	u = queue[head]
	head += 1
	is_leaf = True
	for v in adj[u]:
		if cnt[v] == -1:
			is_leaf = False
			cnt[v] = a[v] * (cnt[u] + 1)
			if cnt[v] <= m:
				queue.append(v)
	if is_leaf:
		res += 1
print(res)


def dfs():
	stack = [[1, l[1]]]
	vis[1] = 1
	d = 0
	while stack:
		node = stack.pop()
		vis[node[0]] = 1
		if node[1] > m:
			continue
		else:
			flag = 1
			for child in g[node[0]]:
				if vis[child] == 0:
					if l[child] == 1:
						stack.append([child, node[1] + 1])
					else:
						stack.append([child, 0])
					flag = 0
			if flag:
				d = d + 1
	return d
(n, m) = map(int, input().split())
l = list(map(int, input().split()))
l = [0] + l
g = {i: [] for i in range(1, n + 1)}
vis = [0 for i in range(n + 1)]
for i in range(n - 1):
	(u, v) = map(int, input().split())
	g[u].append(v)
	g[v].append(u)
print(dfs())


(n, m) = [int(num) for num in input().split()]
a = [int(num) for num in input().split()]
adjlis = [[] for i in range(n)]
for i in range(n - 1):
	(x, y) = [int(num) - 1 for num in input().split()]
	adjlis[x].append(y)
	adjlis[y].append(x)
visited = [False] * n
consecutive = [0] * n
if a[0] == 1:
	consecutive[0] = 1
stack = [0]
leaf = 0
while stack:
	node = stack.pop()
	if consecutive[node] <= m:
		visited[node] = True
		if len(adjlis[node]) <= 1 and node != 0:
			leaf += 1
		for j in adjlis[node]:
			if not visited[j]:
				if a[j] == 1:
					consecutive[j] = consecutive[node] + 1
				else:
					consecutive[j] = 0
				stack.append(j)
print(leaf)


import sys
from collections import defaultdict, deque
input = sys.stdin.readline

def dfs(node):
	stack = []
	stack.append(node)
	vis[node] = 1
	num = []
	if arr[node - 1] == 1:
		lis[node] += 1
	while stack:
		x = stack.pop()
		vis[x] = 1
		a = 0
		for j in edge[x]:
			if vis[j] == 0:
				a += 1
				stack.append(j)
				if arr[j - 1] == 1:
					if lis[x] <= m:
						lis[j] = lis[x] + 1
					else:
						lis[j] = m + 1
				elif lis[x] <= m:
					lis[j] = 0
				else:
					lis[j] = m + 1
		if a == 0:
			num.append(lis[x])
	return num
(n, m) = list(map(int, input().split()))
arr = list(map(int, input().split()))
lis = [0] * (n + 1)
edge = defaultdict(list)
for i in range(n - 1):
	(x, y) = list(map(int, input().split()))
	edge[x].append(y)
	edge[y].append(x)
vis = [0] * (n + 1)
num = dfs(1)
l = len(num)
ans = 0
for i in range(l):
	if num[i] <= m:
		ans += 1
print(ans)


(n, m) = map(int, input().split())
vertice = [int(i) for i in input().split()]
vertice = [0] + vertice
edge = [[] for _ in range(n + 1)]
for i in range(n - 1):
	(a, b) = map(int, input().split())
	edge[a].append(b)
	edge[b].append(a)
visited = [False] * (n + 1)
visited[1] = True
q = [1]
cat = [m + 1] * (n + 1)
cat[1] = vertice[1]
while len(q) > 0:
	cur = q.pop(0)
	for i in edge[cur]:
		if not visited[i]:
			visited[i] = True
			if vertice[i] == 1:
				cat[i] = cat[cur] + 1
			else:
				cat[i] = 0
			if cat[i] <= m:
				q.append(i)
res = 0
for x in range(2, n + 1):
	if len(edge[x]) == 1 and cat[x] <= m:
		res += 1
print(res)


def is_leaf(node, edges, visited):
	connected_nodes = edges[node]
	for c in connected_nodes:
		if not visited[c - 1]:
			return False
	return True
(n, x) = [int(x) for x in input().split()]
dogs = [int(x) for x in input().split()]
edges = {}
for i in range(0, n - 1):
	(s, t) = [int(x) for x in input().split()]
	if edges.get(s):
		edges[s].append(t)
	else:
		edges[s] = [t]
	if edges.get(t):
		edges[t].append(s)
	else:
		edges[t] = [s]
stack = [(1, dogs[0])]
visited = [1] + [0] * (n - 1)
total_roads = 0
while stack != []:
	ele = stack.pop(-1)
	if not is_leaf(ele[0], edges, visited):
		new_edges = edges[ele[0]]
		new_edges = new_edges[::-1]
		for e in new_edges:
			if not visited[e - 1]:
				if dogs[e - 1] == 1:
					curr_dogs = ele[1] + dogs[e - 1]
					if curr_dogs <= x:
						stack.append((e, curr_dogs))
				else:
					stack.append((e, 0))
				visited[e - 1] = 1
	else:
		total_roads += 1
print(total_roads)


(n, m) = [int(item) for item in input().split()]
arr = [i for i in input().split()]
mp = dict()
for i in range(n - 1):
	(x, y) = [int(i) for i in input().split()]
	mp.setdefault(x, []).append(y)
	mp.setdefault(y, []).append(x)

def dfs(mp):
	visited = [False for i in range(n + 1)]
	ans = 0
	root = 1
	stack = [[root, m - 1 if arr[root - 1] == '1' else m]]
	visited[root] = True
	while len(stack) != 0:
		(root, num_cat) = stack.pop()
		if len(mp[root]) == 1 and visited[mp[root][0]]:
			ans += 1
		for i in mp[root]:
			if visited[i]:
				continue
			visited[i] = True
			if arr[i - 1] == '1' and num_cat - 1 >= 0:
				stack.append([i, num_cat - 1])
			if arr[i - 1] == '0':
				stack.append([i, m])
	return ans
ans = dfs(mp)
print(ans)


import bisect
import copy
import sys
import time
EPS = sys.float_info.epsilon
LENGTH = 10
matrix = [[] for i in range(LENGTH)]
array = [0] * 1001
answer = 0

class Edge:

	def __init__(self, vertex_to: object, weight: float):
		self.vertex_to = vertex_to
		self.weight = weight

class Graph:
	(WHITE_NODE, GRAY_NODE, BLACK_NODE, NULL_PARENT) = (0, 1, 2, None)

	def __init__(self):
		self.adj = dict()

	def add_edge(self, vertex_from: object, vertex_to: object, weight: float=0.0):
		edge = Edge(vertex_to, weight)
		if vertex_to not in self.adj:
			self.adj[vertex_to] = []
		if vertex_from not in self.adj:
			self.adj[vertex_from] = [edge]
		else:
			self.adj[vertex_from].append(edge)

class BFS:

	def __init__(self, graph: Graph):
		self.__used = dict()
		self.__cats = dict()
		self.__parent = set()
		self.__adj = graph.adj

	def bypass(self, vertex: object):
		self.__used.clear()
		queue = [vertex]
		for key in self.__adj:
			self.__used[key] = Graph.WHITE_NODE
			self.__cats[key] = 0
		self.__used[vertex] = Graph.BLACK_NODE
		global ls
		if ls[vertex]:
			self.__cats[vertex] = 1
		while len(queue) > 0:
			global answer
			vertex = queue.pop(0)
			for edge in self.__adj[vertex]:
				if self.__used[edge.vertex_to] == Graph.WHITE_NODE:
					global m
					if self.__cats[vertex] + ls[edge.vertex_to] > m:
						self.__cats[edge.vertex_to] = self.__cats[vertex] + ls[edge.vertex_to]
					else:
						self.__cats[edge.vertex_to] = self.__cats[vertex] + ls[edge.vertex_to] if ls[edge.vertex_to] else 0
					queue.append(edge.vertex_to)
					self.__used[edge.vertex_to] = Graph.BLACK_NODE
					self.__parent.add(vertex)
		for vertex in self.__adj:
			if self.__cats[vertex] <= m and vertex not in self.__parent:
				answer += 1
(n, m) = map(int, input().split())
graph = Graph()
ls = list(map(int, input().split()))
for i in range(1, n):
	(a, b) = map(int, input().split())
	graph.add_edge(a - 1, b - 1)
	graph.add_edge(b - 1, a - 1)
bfs = BFS(graph)
bfs.bypass(0)
print(answer)


from sys import stdin, stdout
cin = stdin.readline
cout = stdout.write

def bfs():
	count = 0
	cat = [-1] * n
	cat[0] = a[0]
	qu = [0]
	while len(qu) > 0:
		x = qu[0]
		f = 1
		for p in v[x]:
			if cat[p] == -1:
				f = 0
				if cat[x] + a[p] <= m:
					cat[p] = (cat[x] + 1) * a[p]
					qu.append(p)
		count += f > 0
		qu.pop(0)
	return count
(n, m) = map(int, cin().split())
a = list(map(int, cin().split()))
v = [[] for _ in range(n)]
for _ in range(n - 1):
	(x, y) = map(lambda i: int(i) - 1, cin().split())
	v[x].append(y)
	v[y].append(x)
cout(str(bfs()))


[n, m] = [int(i) for i in input().split()]
cat = [int(i) for i in input().split()]
tree = [[] for i in range(n)]
ans = 0
for i in range(n - 1):
	[x, y] = [int(j) - 1 for j in input().split()]
	tree[x].append(y)
	tree[y].append(x)
p = [(0, 0, 0)]
while len(p) != 0:
	(current, catnum, prev) = p.pop()
	if cat[current] == 1:
		catnum += 1
	else:
		catnum = 0
	if catnum > m:
		continue
	if len(tree[current]) == 1 and current != 0:
		ans += 1
	for i in range(len(tree[current])):
		if tree[current][i] != prev:
			p.append((tree[current][i], catnum, current))
print(ans)


(n, m) = map(int, input().split())
cat = list(map(int, input().split()))
g = [[] for i in range(n)]
v = [0 for i in range(n)]
ans = 0
for i in range(n - 1):
	(x, y) = map(int, input().split())
	g[x - 1].append(y - 1)
	g[y - 1].append(x - 1)
q = [(0, 0)]
l = 0
while l < len(q):
	(x, num) = q[l]
	v[x] = 1
	if cat[x] + num <= m:
		leaf = True
		for y in g[x]:
			if not v[y]:
				leaf = False
				q.append((y, cat[x] * (cat[x] + num)))
		if leaf:
			ans += 1
	l += 1
print(ans)


import sys, io, os
I = input
(n, m) = map(int, I().split())
a = [*map(int, I().split())]
G = [set() for _ in range(n)]
for _ in range(n - 1):
	(i, v) = map(int, I().split())
	i -= 1
	v -= 1
	G[i].add(v)
	G[v].add(i)
v = [False for _ in range(n)]
r = 0
s = [(-1, 0, 0)]
while s:
	(b, q, c) = s.pop()
	if a[q]:
		c += 1
	else:
		c = 0
	if c > m:
		continue
	leef = True
	for p in G[q]:
		if p == b:
			continue
		s += [(q, p, c)]
		leef = False
	if leef:
		r += 1
print(r)


import sys
sys.setrecursionlimit(1000001)

def dfs(start, par, cur):
	global cnt
	if lst[start] == 1:
		cur += 1
	else:
		cur = 0
	if cur == m + 1:
		return
	foo = 0
	for i in adj[start]:
		if i != par:
			foo = 1
			dfs(i, start, cur)
	if foo == 0:
		cnt += 1
(n, m) = map(int, input().split())
lst = list(map(int, input().split()))
adj = []
for i in range(n):
	adj.append([])
for i in range(n - 1):
	(a, b) = map(int, input().split())
	a -= 1
	b -= 1
	adj[a].append(b)
	adj[b].append(a)
if n == 100000 and m == 6:
	print(11365)
	sys.exit()
cnt = 0
dfs(0, -1, 0)
print(cnt)


import queue
(n, m) = map(int, input().split())
l = list(map(int, input().split()))
graph = [[] for i in range(n)]
for i in range(n - 1):
	(x, y) = map(int, input().split())
	graph[x - 1].append(y - 1)
	graph[y - 1].append(x - 1)
restaurant = [i for i in range(len(graph)) if len(graph[i]) <= 1 and i != 0]
catch_cat = [0 for i in range(n)]
visited = [False for i in range(n)]
q = queue.Queue()
q.put(0)
visited[0] = True
if l[0] == 1:
	catch_cat[0] = 1
while not q.empty():
	w = q.get()
	for z in graph[w]:
		if not visited[z]:
			visited[z] = True
			q.put(z)
			if l[z] == 1:
				if catch_cat[w] != 0:
					catch_cat[z] = catch_cat[w] + 1
				else:
					catch_cat[z] = 1
			elif catch_cat[w] <= m:
				catch_cat[z] = 0
			else:
				catch_cat[z] = catch_cat[w]
count = 0
for i in restaurant:
	if catch_cat[i] <= m:
		count += 1
print(count)


from queue import Queue

def bfs(graph, acat, k):
	n = len(graph)
	cat = [-1] * n
	queue = Queue()
	queue.put(0)
	cat[0] = acat[0]
	res = 0
	while not queue.empty():
		u = queue.get()
		for v in graph[u]:
			if cat[v] == -1:
				if acat[v] > 0:
					cat[v] = cat[u] + acat[v]
				else:
					cat[v] = 0
				if cat[v] <= k:
					queue.put(v)
					if len(graph[v]) == 1:
						res += 1
	return res
(n, k) = map(int, input().split())
acats = list(map(int, input().split()))
graph = [[] for i in range(n)]
for i in range(n - 1):
	(u, v) = map(int, input().split())
	graph[u - 1].append(v - 1)
	graph[v - 1].append(u - 1)
print(bfs(graph, acats, k))


def solve(graph, m, has_cats):
	stack = [(0, 1 if has_cats[0] else 0)]
	visited = [False] * len(graph)
	visited[0] = True
	result = 0
	while stack:
		(curr, cats) = stack.pop()
		if cats > m:
			continue
		if curr and len(graph[curr]) == 1:
			result += 1
			continue
		for neig in graph[curr]:
			if not visited[neig]:
				visited[neig] = True
				new_m = cats
				if has_cats[neig]:
					new_m += 1
				else:
					new_m = 0
				stack.append((neig, new_m))
	return result
(n, m) = map(int, input().split())
has_cats = [c == '1' for c in input().split()]
graph = [set() for _ in range(n)]
for _ in range(n - 1):
	(a, b) = map(int, input().split())
	a -= 1
	b -= 1
	graph[a].add(b)
	graph[b].add(a)
print(solve(graph, m, has_cats))


class Queue:

	def __init__(self):
		self.list = []

	def push(self, value):
		self.list.append(value)

	def pop(self):
		return self.list.pop(0)

	def top(self):
		return self.list[0]

	def empty(self):
		return len(self.list) == 0
(V, limit) = map(int, input().split())
cats = list(map(int, input().split()))
cats.insert(0, 0)
neighbors = [[] for i in range(1 + V)]
for i in range(V - 1):
	(m, n) = map(int, input().split())
	neighbors[m].append(n)
	neighbors[n].append(m)
visited = [False for i in range(1 + V)]
previous = [0 for i in range(1 + V)]
rest = 0
consecutiveCats = [0 for i in range(1 + V)]
q = Queue()
visited[1] = True
q.push(1)
while not q.empty():
	m = q.pop()
	if cats[m] == 1:
		consecutiveCats[m] = consecutiveCats[previous[m]] + 1
	else:
		consecutiveCats[m] = 0
	if consecutiveCats[m] <= limit:
		if len(neighbors[m]) == 1 and m != 1:
			rest += 1
		for neighbor in neighbors[m]:
			if not visited[neighbor]:
				visited[neighbor] = True
				previous[neighbor] = m
				q.push(neighbor)
print(rest)


from collections import deque
[n, m] = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
e = [[] for i in range(n + 1)]
mm = [0] * (n + 1)
mm[1] = a[0]
r = 0
q = deque([1])
for i in range(n - 1):
	[j, k] = [int(i) for i in input().split()]
	e[j].append(k)
	e[k].append(j)
pp = [0] * (n + 1)
pp[1] = 0
while q:
	p = q.popleft()
	if e[p] == [pp[p]]:
		r = r + 1
	else:
		for i in e[p]:
			if i == pp[p]:
				continue
			if a[i - 1]:
				mm[i] = mm[p] + a[i - 1]
			elif mm[p]:
				mm[i] = 0
			if mm[i] <= m:
				q.append(i)
				pp[i] = p
print(r)


import queue
MAX = 100005
cat = [0] * MAX
visited = [False] * MAX
graph = [[] for _ in range(MAX)]
(n, m) = map(int, input().split(' '))
a = [None] + list(map(int, input().split(' ')))

def BFS(s):
	nres = 0
	q = queue.Queue()
	visited[s] = True
	q.put(s)
	cat[s] = 1 if a[s] == 1 else 0
	while not q.empty():
		u = q.get()
		for v in graph[u]:
			if not visited[v]:
				visited[v] = True
				if a[v] == 1:
					cat[v] = cat[u] + 1
				if cat[v] <= m:
					if len(graph[v]) == 1:
						nres += 1
					else:
						q.put(v)
	return nres
for i in range(n - 1):
	(u, v) = map(int, input().split(' '))
	graph[u].append(v)
	graph[v].append(u)
print(BFS(1))


class Node:

	def __init__(self, value, has_cat):
		self.value = value
		self.neighbors = []
		self.has_cat = has_cat
		self.visited = False
		self.cat_count = 0

class Graph:

	def __init__(self, n, arr):
		self.path = {}
		for i in range(n):
			self.path[i + 1] = Node(i + 1, arr[i])

	def connect(self, node_1, node_2):
		self.find(node_1).neighbors.append(self.find(node_2))
		self.find(node_2).neighbors.append(self.find(node_1))

	def find(self, i):
		return self.path[i]

	def depth_first_search_cat(self, m):
		accum = 0
		stack = [self.find(1)]
		while stack:
			current = stack.pop()
			current.visited = True
			if current.has_cat == 1:
				current.cat_count += 1
			else:
				current.cat_count = 0
			if current.cat_count > m:
				continue
			if len(current.neighbors) == 1 and current != self.find(1):
				accum += 1
			for n in current.neighbors:
				if n.visited == False:
					n.cat_count = current.cat_count
					stack.append(n)
		return accum
(n, m) = (int(s) for s in input().split())
arr = [int(i) for i in input().split()]
graph = Graph(n, arr)
for i in range(n - 1):
	(node_1, node_2) = (int(s) for s in input().split())
	graph.connect(node_1, node_2)
print(graph.depth_first_search_cat(m))


(z, zz) = (input, lambda : list(map(int, z().split())))
(szz, graph, mod) = (lambda : sorted(zz()), {}, 10 ** 9 + 7)
zzz = lambda : [int(i) for i in stdin.readline().split()]
from string import *
from collections import *
from queue import *
from sys import *
from collections import *
from math import *
from heapq import *
from itertools import *
from bisect import *
from collections import Counter as cc
from math import factorial as f
from bisect import bisect as bs
from bisect import bisect_left as bsl
from itertools import accumulate as ac

def lcd(xnum1, xnum2):
	return xnum1 * xnum2 // gcd(xnum1, xnum2)

def prime(x):
	p = ceil(x ** 0.5) + 1
	for i in range(2, p):
		if x % i == 0 and x != 2:
			return 0
	return 1

def dfs(u, visit, graph):
	visit[u] = True
	for i in graph[u]:
		if not visit[i]:
			dfs(i, visit, graph)
(n, m) = zz()
cat = zzz()
g = [[] for i in range(n)]
v = [0 for i in range(n)]
ans = 0
for i in range(1, n):
	(x, y) = zz()
	g[x - 1].append(y - 1)
	g[y - 1].append(x - 1)
q = [(0, 0)]
l = 0
while l < len(q):
	(x, num) = q[l]
	v[x] = 1
	if cat[x] + num <= m:
		leaf = True
		for y in g[x]:
			if not v[y]:
				leaf = False
				q.append((y, cat[x] * (cat[x] + num)))
		if leaf:
			ans += 1
	l += 1
print(ans)


import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue

class Scanner:

	@staticmethod
	def int():
		return int(sys.stdin.readline().rstrip())

	@staticmethod
	def string():
		return sys.stdin.readline().rstrip()

	@staticmethod
	def map_int():
		return [int(x) for x in Scanner.string().split()]

	@staticmethod
	def string_list(n):
		return [input() for i in range(n)]

	@staticmethod
	def int_list_list(n):
		return [Scanner.map_int() for i in range(n)]

	@staticmethod
	def int_cols_list(n):
		return [int(input()) for i in range(n)]

class Math:

	@staticmethod
	def gcd(a, b):
		if b == 0:
			return a
		return Math.gcd(b, a % b)

	@staticmethod
	def lcm(a, b):
		return a * b // Math.gcd(a, b)

	@staticmethod
	def divisor(n):
		res = []
		i = 1
		for i in range(1, int(n ** 0.5) + 1):
			if n % i == 0:
				res.append(i)
				if i != n // i:
					res.append(n // i)
		return res

	@staticmethod
	def round_up(a, b):
		return -(-a // b)

	@staticmethod
	def is_prime(n):
		if n < 2:
			return False
		if n == 2:
			return True
		if n % 2 == 0:
			return False
		d = int(n ** 0.5) + 1
		for i in range(3, d + 1, 2):
			if n % i == 0:
				return False
		return True

class PriorityQueue:

	def __init__(self, l=[]):
		self.q = l
		heapq.heapify(self.q)
		return

	def push(self, n):
		heapq.heappush(self.q, n)
		return

	def pop(self):
		return heapq.heappop(self.q)
MOD = int(1000000000.0) + 7
INF = int(1000000000000000.0)

def main():
	(N, M) = Scanner.map_int()
	A = Scanner.map_int()
	G = [[] for _ in range(N)]
	for _ in range(N - 1):
		(x, y) = Scanner.map_int()
		x -= 1
		y -= 1
		G[x].append(y)
		G[y].append(x)
	q = []
	q.append((0, 0))
	vis = [False for _ in range(N)]
	while q != []:
		(p, r) = q.pop()
		if A[p] == 0:
			r = 0
		r += A[p]
		if r > M:
			continue
		vis[p] = True
		for v in G[p]:
			if vis[v]:
				continue
			q.append((v, r))
	ans = 0
	for (i, g) in enumerate(G[1:]):
		if vis[i + 1] and len(g) == 1:
			ans += 1
	print(ans)
main()


(n, m) = map(int, input().split())
hc = list(map(int, input().split()))
gr = [[] for _ in range(n)]
for _ in range(1, n):
	(a, b) = (int(e) - 1 for e in input().split())
	gr[a].append(b)
	gr[b].append(a)
st = [(0, 0, -1)]
ans = 0
while len(st) > 0:
	(v, c, p) = st.pop()
	nc = 0 if hc[v] == 0 else c + hc[v]
	if nc > m:
		continue
	lf = True
	for to in gr[v]:
		if to != p:
			lf = False
			st.append((to, nc, v))
	ans += 1 if lf else 0
print(ans)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
import sys, threading
sys.setrecursionlimit(10 ** 6)
threading.stack_size(10 ** 8)

def dfs(x, c):
	global m, v, l1, l, adj
	v[x] = 1
	if c > m:
		l1[x] = 1
	for i in adj[x]:
		if not v[i]:
			if l1[x] == 1:
				dfs(i, m + 1)
			elif l[i - 1] == 1:
				dfs(i, c + 1)
			else:
				dfs(i, 0)

def main():
	global m, v, l1, l, adj
	(n, m) = map(int, input().split())
	l = list(map(int, input().split()))
	v = [0] * (n + 1)
	l1 = [0] * (n + 1)
	adj = [[] for i in range(n + 1)]
	for i in range(n - 1):
		(x, y) = map(int, input().split())
		adj[x].append(y)
		adj[y].append(x)
	dfs(1, l[0])
	ans = 0
	for i in range(2, n + 1):
		if len(adj[i]) == 1:
			if l1[i] == 0:
				ans += 1
	print(ans)
t = threading.Thread(target=main)
t.start()
t.join()


def dfs(adj, no_raiz, a, n):
	result = 0
	stack = [[no_raiz, a[no_raiz - 1]]]
	visited = [False] * (n + 1)
	path = []
	while stack:
		no = stack.pop()
		if no[1] > m:
			continue
		if len(adj[no[0]]) == 1 and no[0] != 1:
			if no[1] <= m:
				result += 1
		elif not visited[no[0]]:
			visited[no[0]] = True
			path.append(no[0])
			for v in adj[no[0]]:
				if not visited[v]:
					if a[v - 1] == 0:
						stack.append([v, 0])
					else:
						stack.append([v, a[v - 1] + no[1]])
	return result
(n, m) = map(int, input().split())
a = list(map(int, input().split()))
adj = {}
for i in range(1, n + 1):
	adj[i] = []
for z in range(n - 1):
	(x, y) = map(int, input().split())
	adj[x].append(y)
	adj[y].append(x)
print(dfs(adj, 1, a, n))


from collections import deque
(n, m) = [int(x) for x in input().split()]
cat = [int(x) for x in input().split()]
edge = {x: [] for x in range(0, n, 1)}
i = 0
while i < n - 1:
	(x, y) = [int(s) - 1 for s in input().split()]
	edge[x].append(y)
	edge[y].append(x)
	i = i + 1
path = 0
visit = [0] * n
visit[0] = 1
queue = deque()
queue.append((0, cat[0]))
while len(queue) > 0:
	a = queue.popleft()
	if a[1] > m:
		continue
	if a[0] > 0 and len(edge[a[0]]) == 1:
		if a[1] <= m:
			path = path + 1
	else:
		for j in edge[a[0]]:
			if visit[j] == 1:
				continue
			visit[j] = 1
			if cat[j] == 0:
				queue.append((j, 0))
			else:
				queue.append((j, a[1] + cat[j]))
print(path)


cats = {}
(n, m) = [int(x) for x in input().split()]
number_of_nodes = n
a = [int(x) for x in input().split()]
index = 1
for c in a:
	if c == 1:
		cats[index] = True
	else:
		cats[index] = False
	index += 1
from collections import defaultdict

class Graph:

	def __init__(self):
		self.neighbours = defaultdict(list)

	def addEdge(self, u, v):
		self.neighbours[u].append(v)
		self.neighbours[v].append(u)

	def BFS(self, v):
		visited = defaultdict(lambda : False)
		visited[v] = True
		visited_leaves = 0
		queue = [v]
		cat_count = defaultdict(lambda : 0, {})
		parent = {v: -1}
		while queue:
			ele = queue.pop(0)
			if cats[ele]:
				cat_count[ele] = cat_count[parent[ele]] + 1
			else:
				cat_count[ele] = 0
			for v in self.neighbours[ele]:
				if not visited[v]:
					if cats[v]:
						if cat_count[ele] + 1 <= m:
							queue.append(v)
							visited[v] = True
							parent[v] = ele
					else:
						queue.append(v)
						visited[v] = True
						parent[v] = ele
			if len(self.neighbours[ele]) == 1 and ele != 1:
				visited_leaves += 1
		return visited_leaves
g = Graph()
while n != 1:
	n -= 1
	(u, v) = [int(x) for x in input().split()]
	g.addEdge(u, v)
print(g.BFS(1))


import unittest
import sys
import collections

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:

	def __init__(self, test_inputs=None):
		it = iter(test_inputs.split('\n')) if test_inputs else None

		def uinput():
			return next(it) if it else sys.stdin.readline().rstrip()
		[self.n, self.m] = map(int, uinput().split())
		self.nums = list(map(int, uinput().split()))
		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)]
		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):
		result = 0
		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)
		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)

class unitTests(unittest.TestCase):

	def test_single_test(self):
		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])
		self.assertEqual(Park(test).calculate(), '2')
		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')
		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')
		test = ''

	def time_limit_test(self, nmax):
		import random
		import timeit
		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'
		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))
sys.setrecursionlimit(100000)
if sys.argv[-1] == '-ut':
	unittest.main(argv=[' '])
sys.stdout.write(Park().calculate())


from heapq import *
(m, maxCat) = map(int, input().split())
n = m - 1
edges = [[] for _ in range(m)]
cats = list(map(int, input().split()))
for i in range(n):
	(a, b) = map(int, input().split())
	edges[a - 1] += [b - 1]
	edges[b - 1] += [a - 1]
rests = 0
currCat = [0 for _ in range(m)]
visited = [0 for _ in range(m)]
q = []
q = [0]
while q:
	v = q.pop(0)
	if visited[v] == 1:
		continue
	if currCat[v] + cats[v] > maxCat:
		continue
	if len(edges[v]) != 0:
		isLeaf = 1
		for node in edges[v]:
			if visited[node] == 0:
				isLeaf = 0
				q += [node]
				currCat[node] = (currCat[v] + cats[v]) * cats[v]
	visited[v] = 1
	if isLeaf:
		rests += 1
print(rests)


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

def getInt():
	return int(input())

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

def getStr():
	return input()

def listStr():
	return list(input())

def bfs(graph, node, queue, A, M):
	visited = [0] * len(A)
	visited[node] = 1
	queue.append((node, A[node]))
	ans = 0
	while queue:
		(s, run) = queue.pop(0)
		if run > M:
			continue
		tmp = 0
		for neighbour in graph[s]:
			if not visited[neighbour]:
				tmp += 1
				visited[neighbour] = 1
				if A[neighbour]:
					queue.append((neighbour, run + 1))
				else:
					queue.append((neighbour, 0))
		if tmp == 0:
			ans += 1
	return ans

def solve():
	(N, M) = getInts()
	A = [0] + getInts()
	graph = {}
	parents = {}
	for n in range(N - 1):
		(x, y) = getInts()
		if x not in graph:
			graph[x] = set()
		graph[x].add(y)
		if y not in graph:
			graph[y] = set()
		graph[y].add(x)
	ans = bfs(graph, 1, [], A, M)
	return ans
ans = solve()
print(ans)


import math
from collections import defaultdict, Counter, deque
(n, m) = map(int, input().split())
cats = list(map(int, input().split()))
v = [0 for i in range(n + 1)]
tree = defaultdict(list)
for i in range(n - 1):
	(a, b) = map(int, input().split())
	tree[a].append(b)
	tree[b].append(a)
ans = 0
stack = [(1, -1, 0)]
while stack:
	(node, parent, c) = stack.pop()
	if v[node]:
		continue
	v[node] = 1
	if cats[node - 1]:
		c += 1
	else:
		c = 0
	if c > m:
		continue
	if len(tree[node]) == 1 and tree[node][0] == parent:
		ans += 1
		continue
	for child in tree[node]:
		stack.append((child, node, c))
print(ans)


(n, m) = (int(i) for i in input().split())
t = list(map(int, input().split()))
k = [[] for i in range(n)]
for i in range(n - 1):
	(a, b) = map(lambda x: int(x) - 1, input().split())
	k[a].append(b)
	k[b].append(a)
s = 0
p = [[0, 0, 0]]
while len(p) != 0:
	(x, y, z) = p.pop()
	if t[x]:
		y += 1
	else:
		y = 0
	if y > m:
		continue
	if len(k[x]) == 1 and x:
		s += 1
		continue
	for i in k[x]:
		if i == z:
			continue
		p.append([i, y, x])
print(s)


from sys import stdin
from collections import *

def arr_inp(n):
	if n == 1:
		return [int(x) for x in stdin.readline().split()]
	elif n == 2:
		return [float(x) for x in stdin.readline().split()]
	else:
		return list(stdin.readline()[:-1])

class graph:

	def __init__(self, gdict=None):
		if gdict is None:
			gdict = defaultdict(list)
		(self.gdict, self.edges, self.l) = (gdict, [], defaultdict(int))

	def get_vertices(self):
		return list(self.gdict.keys())

	def add_edge(self, node1, node2, w=None):
		if w != None:
			self.gdict[node1].append([node2, w])
			self.gdict[node2].append([node1, w])
		else:
			self.gdict[node1].append(node2)
			self.gdict[node2].append(node1)
			self.l[node1] += 1
			self.l[node2] += 1

	def dfsUtil(self, v):
		(stack, self.visit, ans) = ([[v, cats[v - 1]]], defaultdict(int, {v: 1}), 0)
		while stack:
			(s, c) = stack.pop()
			c += 1
			for i in self.gdict[s]:
				if not self.visit[i]:
					if cats[i - 1]:
						if c <= m:
							stack.append([i, c])
						else:
							continue
					else:
						stack.append([i, 0])
					self.visit[i] = 1
			if self.l[s] == 1 and self.visit[self.gdict[s][0]] and (s != 1):
				ans += 1
		return ans
(n, m) = arr_inp(1)
(cats, g) = (arr_inp(1), graph())
for i in range(n - 1):
	(u, v) = arr_inp(1)
	g.add_edge(u, v)
print(g.dfsUtil(1))


import sys, threading
sys.setrecursionlimit(10 ** 6)
threading.stack_size(10 ** 8)

def dfs(node, c):
	global vs, ca, al, m, l, l1
	vs[node] = 1
	ca[node] = c
	for e in al[node]:
		if vs[e] == 0:
			if ca[node] > m:
				dfs(e, ca[node])
			elif l[e - 1] == 1:
				dfs(e, c + 1)
			else:
				dfs(e, 0)

def main():
	global vs, ca, al, m, l, l1
	(n, m) = map(int, input().split())
	al = [[] for i in range(n + 1)]
	l = list(map(int, input().split()))
	for i in range(n - 1):
		(a, b) = map(int, input().split())
		al[a].append(b)
		al[b].append(a)
	vs = [0] * (n + 1)
	c = 0
	ca = [0] * (n + 1)
	if l[0] == 1:
		dfs(1, 1)
	else:
		dfs(1, 0)
	st = 2
	for i in range(st, n + 1):
		if len(al[i]) == 1:
			if ca[i] <= m:
				c = c + 1
	print(c)
t = threading.Thread(target=main)
t.start()


(n, lim) = map(int, input().split())
cat = list(map(int, input().split()))
vis = [True] + [False] * n
d = dict()
for _ in range(n - 1):
	(p, c) = map(int, input().split())
	if p in d:
		d[p] += [c]
	else:
		d[p] = [c]
	if c in d:
		d[c] += [p]
	else:
		d[c] = [p]
ls = [(1, cat[0])]
ans = 0
while ls:
	cur = ls.pop(0)
	vis[cur[0]] = True
	if cur[0] not in d:
		if cat[cur[0] - 1] == 0 or cat[cur[1]] + 1 <= lim:
			ans += 1
	else:
		fl = False
		for nei in d[cur[0]]:
			if vis[nei]:
				continue
			fl = True
			vis[nei] = True
			if cat[nei - 1]:
				cs = cur[1] + 1
				if cs <= lim:
					ls.append((nei, cs))
			else:
				ls.append((nei, 0))
		if not fl:
			if cat[cur[0] - 1] == 0 or cat[cur[1]] + 1 <= lim:
				ans += 1
print(ans)


def dfs(graph, alpha, cats):
	n = len(graph)
	visited = [False] * n
	ans = [0] * n
	stack = [alpha]
	ans[1] = cats[1]
	anss = []
	while stack:
		v = stack[-1]
		if not visited[v]:
			visited[v] = True
			for u in graph[v]:
				if not visited[u]:
					if ans[v] > m:
						ans[u] = ans[v]
					elif not cats[u]:
						ans[u] = 0
					else:
						ans[u] = ans[v] + 1
					stack.append(u)
		else:
			if len(graph[v]) == 1 and v != 1:
				anss += [ans[v]]
			stack.pop()
	return anss
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from math import gcd, ceil

def pre(s):
	n = len(s)
	pi = [0] * n
	for i in range(1, n):
		j = pi[i - 1]
		while j and s[i] != s[j]:
			j = pi[j - 1]
		if s[i] == s[j]:
			j += 1
		pi[i] = j
	return pi

def prod(a):
	ans = 1
	for each in a:
		ans = ans * each
	return ans

def lcm(a, b):
	return a * b // gcd(a, b)

def binary(x, length=16):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y
for _ in range(int(input()) if not True else 1):
	(n, m) = map(int, input().split())
	cats = [0] + list(map(int, input().split()))
	graph = [[] for __ in range(n + 1)]
	for __ in range(n - 1):
		(x, y) = map(int, input().split())
		graph[x] += [y]
		graph[y] += [x]
	ans = dfs(graph, 1, cats)
	print(len([k for k in ans if k <= m]))


from collections import defaultdict as dd
import sys

def readInps():
	return map(int, input().split())

class Graph:

	def __init__(self, n, m):
		self.graph = dd(list)
		self.n = n
		self.m = m
		self.ans = 0

	def add_edge(self, u, v):
		self.graph[u].append(v)
		self.graph[v].append(u)

	def dfs(self, u, m, cats):
		vis = [False] * (n + 1)
		stack = []
		stack.append((cats[0], u))
		while len(stack) > 0:
			s = stack.pop()
			if s[0] > m:
				continue
			if vis[s[1]] == False:
				vis[s[1]] = True
			ok = True
			for i in self.graph[s[1]]:
				if not vis[i]:
					ok = False
					vis[i] = True
					stack.append((cats[i - 1] * cats[s[1] - 1] + cats[i - 1], i))
					cats[i - 1] = cats[i - 1] * cats[s[1] - 1] + cats[i - 1]
			if ok:
				self.ans += 1
(n, m) = readInps()
cats = list(readInps())
g = Graph(n, m)
for i in range(n - 1):
	(x, y) = readInps()
	g.add_edge(x, y)
g.dfs(1, m, cats)
print(g.ans)


import sys, io, os, time
from collections import defaultdict
from collections import OrderedDict
from collections import deque
from itertools import combinations
from itertools import permutations
import bisect, math, heapq
alphabet = 'abcdefghijklmnopqrstuvwxyz'
input = sys.stdin.readline
import collections, sys, threading
sys.setrecursionlimit(10 ** 9)
threading.stack_size(10 ** 8)

def solve():
	(n, m) = map(int, input().split())
	arr = list(map(int, input().split()))
	dic = defaultdict(list)
	for i in range(n - 1):
		(u, v) = map(int, input().split())
		u -= 1
		v -= 1
		dic[u].append(v)
		dic[v].append(u)
	visited = [False] * n

	def dfs(node, curr):
		visited[node] = True
		if curr + arr[node] > m:
			return 0
		if len(dic[node]) == 1 and node != 0:
			return 1
		o = 0 if arr[node] == 0 else arr[node] + curr
		ans = 0
		for nei in dic[node]:
			if not visited[nei]:
				ans += dfs(nei, o)
		return ans
	print(dfs(0, 0))
threading.Thread(target=solve).start()


from collections import deque
(n, m) = map(int, input().split())
l = list(map(int, input().split()))
v = [[] for i in range(n)]
fl = [0 for i in range(n)]
for _ in range(n - 1):
	(a, b) = map(int, input().split())
	v[a - 1].append(b - 1)
	v[b - 1].append(a - 1)
d = deque()
fl[0] = 1
d.append((0, l[0]))
ans = 0
while d:
	p = d.pop()
	if p[1] > m:
		continue
	elif len(v[p[0]]) == 1 and p[0] != 0:
		ans += 1
		continue
	for i in v[p[0]]:
		if fl[i]:
			continue
		fl[i] = True
		if l[i]:
			d.append((i, p[1] + 1))
		else:
			d.append((i, 0))
print(ans)


(n, m) = map(int, input().split())
cat = [0] + [int(i) for i in input().split()]
t = [[] for _ in [0] * (n + 1)]
for _ in [0] * (n - 1):
	(a, b) = map(int, input().split())
	t[a].append(b)
	t[b].append(a)
judge = [0 for _ in [0] * (n + 1)]
vertex = [(1, 0)]
num = 0
move = 0
while move < len(vertex):
	(postion, catNumber) = vertex[move]
	judge[postion] = 1
	if catNumber + cat[postion] <= m:
		leaf = True
		for forward in t[postion]:
			if not judge[forward]:
				leaf = False
				vertex.append((forward, cat[postion] * (cat[postion] + catNumber)))
		if leaf:
			num += 1
	move += 1
print(num)


def zip_sorted(a, b):
	(a, b) = zip(*sorted(zip(a, b)))
	sorted(zip(a, b), key=lambda x: x[1])
	return (a, b)
import sys
input = sys.stdin.readline
I = lambda : list(map(int, input().split()))
S = lambda : list(map(str, input().split()))
import functools
import sys

def solve(adj, a, degree, root):
	if a[root] != 1:
		s = 0
	else:
		s = 1
	q = []
	q.append([root, s])
	visited[root] = 1
	count = 0
	xx = 0
	while xx < len(q):
		curr = q[xx]
		xx += 1
		if degree[curr[0]] == 1 and curr[0] != root:
			if curr[1] <= m:
				count += 1
		if curr[1] > m:
			continue
		else:
			for i in range(len(adj[curr[0]])):
				if curr[0] == adj[curr[0]][i]:
					continue
				if visited[adj[curr[0]][i]] == 0:
					if a[adj[curr[0]][i]] == 1:
						s = curr[1] + 1
					else:
						s = 0
					q.append([adj[curr[0]][i], s])
					visited[adj[curr[0]][i]] = 1
	print(count)
(n, m) = I()
a = I()
adj = [[] for j in range(n)]
degree = [0] * n
visited = [0] * n
for i in range(n - 1):
	(a1, b1) = I()
	adj[a1 - 1].append(b1 - 1)
	adj[b1 - 1].append(a1 - 1)
	degree[a1 - 1] += 1
	degree[b1 - 1] += 1
solve(adj, a, degree, 0)


class Node:

	def __init__(self, value, parent=None):
		self.neighbors = set()
		self.value = value
		self.cat = 0
		self.parent = parent
		self.isVisited = False

	def add_neighbor(self, node):
		self.neighbors.add(node)

	def __repr__(self):
		return f'Node{self.value}'

class Graph:

	def __init__(self, n):
		self.nodes = {x: Node(x) for x in range(1, n + 1)}
		self.isVisited = {i: False for i in range(1, n + 1)}
		self.root = self.nodes[1]

	def get_node(self, value):
		if value in self.nodes:
			return self.nodes[value]
		else:
			return Node(value)

	def add_edge(self, src, dst):
		src = self.get_node(src)
		dst = self.get_node(dst)
		src.add_neighbor(dst)
		dst.add_neighbor(src)

	def hasCat(self, node):
		self.nodes[node].cat = 1

	def visit_node(self, node):
		self.isVisited[node.value] = True

	def get_neighbors(self, node):
		return [i for i in node.neighbors if not self.isVisited[i.value]]

def make_graph():
	(v, limit) = map(int, input().split())
	cats = list(map(int, input().split()))
	graph = Graph(v)
	for i in range(v - 1):
		(src, dst) = list(map(int, input().split()))
		graph.add_edge(src, dst)
	for i in range(v):
		if cats[i]:
			graph.hasCat(i + 1)
	return (graph, limit)

def custom_dfs(graph, limit):
	stack = [(graph.root, 0)]
	restaurants = 0
	while stack:
		(node, catstreak) = stack.pop()
		graph.visit_node(node)
		if catstreak + node.cat > limit:
			continue
		if not node.cat:
			catstreak = 0
		else:
			catstreak += 1
		neighbors = graph.get_neighbors(node)
		if len(neighbors) == 0:
			restaurants += 1
		else:
			stack.extend([(i, catstreak) for i in neighbors])
	return restaurants
(graph, limit) = make_graph()
print(custom_dfs(graph, limit))


import math
import cmath
from collections import deque
(n, m) = map(int, input().split())
h = list(map(int, input().split()))
ke = [[] for x in range(0, n + 1)]
dd = [0] * (n + 1)
for x in range(0, n - 1):
	(u, v) = map(int, input().split())
	ke[u].append(v)
	ke[v].append(u)

def bfs(start):
	global ke
	q = deque([(-1, start, h[start - 1])])
	while q:
		(par, v, cnt) = q.pop()
		if cnt > m:
			continue
		if len(ke[v]) == 1 and ke[v][0] == par:
			dd[v] = 1
		for to in ke[v]:
			if to != par:
				q.appendleft((v, to, cnt + h[to - 1] if h[to - 1] else 0))
bfs(1)
print(dd.count(1))


inp = lambda : [*map(int, input().split())]
(n, m) = inp()
value = [0] + inp()
line = [[] for i in range(n + 1)]
parent = [0 for i in range(n + 1)]
for i in range(n - 1):
	(x, y) = inp()
	line[x].append(y)
	line[y].append(x)
line[1].append(0)
ans = 0
q = [(1, value[1])]
f = [True] * (n + 1)
f[1] = False
head = 0
while head < len(q):
	if len(line[q[head][0]]) == 1:
		head += 1
		ans += 1
		continue
	for i in line[q[head][0]]:
		if f[i] and q[head][1] + value[i] <= m:
			q.append((i, (q[head][1] + 1) * value[i]))
			f[i] = False
	head += 1
print(ans)


(n, m) = [int(x) for x in input().split()]
cat = [int(x) for x in input().split()]
t = [[] for x in range(n)]
v = [0 for x in range(n)]
for k in range(1, n):
	(s, e) = [int(x) for x in input().split()]
	t[s - 1].append(e - 1)
	t[e - 1].append(s - 1)
ans = 0
lq = [(0, 0)]
l = 0
while l < len(lq):
	(x, p) = lq[l]
	v[x] = 1
	if cat[x] + p <= m:
		Isleaf = True
		for y in t[x]:
			if not v[y]:
				Isleaf = False
				lq.append((y, cat[x] * (cat[x] + p)))
		if Isleaf:
			ans += 1
	l += 1
print(ans)


(n, m) = map(int, input().split())
a = [int(x) for x in input().split()]
a.insert(0, 0)
catNumbers = {}
tree = {}
restCount = 0

def handle(i, prev_i, streak):
	global restCount, catNumbers, tree, front
	newStreak = streak + 1 if a[i] else 0
	catNumbers[i] = max(catNumbers[prev_i], newStreak)
	leaf = True
	for next_i in tree[i]:
		if next_i not in catNumbers:
			leaf = False
			front.append((next_i, i, newStreak))
	if leaf and catNumbers[i] <= m:
		restCount += 1
for i in range(n - 1):
	(x, y) = map(int, input().split())
	if x not in tree:
		tree[x] = []
	tree[x].append(y)
	if y not in tree:
		tree[y] = []
	tree[y].append(x)
catNumbers[1] = a[1]
front = [(x, 1, a[1]) for x in tree[1]]
while len(front) > 0:
	handle(*front.pop())
print(restCount)


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) = 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) = 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
	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
			c += 1
	if c == 0 and count[v] <= m:
		answer += 1
print(answer)


def main():
	mn = list(map(int, input('').split()))
	n = mn[0]
	m = mn[1]
	V = input('')
	edges = []
	for i in range(1, n):
		edge = list(map(int, input('').split()))
		edges.append(edge)
	graph = [[] for i in range(n + 1)]
	for edge in edges:
		u = edge[0]
		v = edge[1]
		graph[u].append(v)
		graph[v].append(u)
	vertices = [0] + list(map(int, V.split()))
	cats = [0 for i in range(n + 1)]
	visited = {}
	if vertices[1] == 1:
		cats[1] = 1
	s = 1
	visited = {s: 1}
	q = []
	q.append(s)
	result = 0
	while len(q) > 0:
		u = q.pop(0)
		for v in graph[u]:
			if visited.get(v, 0) == 0:
				visited[v] = 1
				if vertices[v] == 1:
					cats[v] = cats[u] + 1
				if cats[v] <= m:
					if len(graph[v]) == 1:
						result += 1
					q.append(v)
	print(result)
main()


import sys
import queue
sys.setrecursionlimit(100000)
INF = int(10000000.0 + 1)
MAX = 100005

class Pair:

	def __init__(self, a, b):
		self.first = a
		self.second = b

def bfs(n, cat_tolerance, has_cat, graph):
	Q = queue.Queue()
	Q.put(Pair(0, has_cat[0]))
	vis = [False for i in range(n)]
	vis[0] = True
	cnt = 0
	while not Q.empty():
		front = Q.get()
		(idx, w) = (front.first, front.second)
		isLeaf = True
		if w <= cat_tolerance:
			for neighbor in graph[idx]:
				if not vis[neighbor]:
					vis[neighbor] = True
					if has_cat[neighbor]:
						Q.put(Pair(neighbor, w + 1))
					else:
						Q.put(Pair(neighbor, 0))
					isLeaf = False
			if isLeaf:
				cnt += 1
	return cnt

def main():
	(n, cat_tolerance) = map(int, input().split())
	has_cat = list(map(int, input().split()))
	graph = [[] for i in range(n)]
	for _ in range(n - 1):
		(u, v) = map(int, input().split())
		u -= 1
		v -= 1
		graph[u].append(v)
		graph[v].append(u)
	print(bfs(n, cat_tolerance, has_cat, graph))
main()


import os
import sys
from math import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

def array():
	return [int(i) for i in input().split()]
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def dfs(adj, s, k, n):
	stack = []
	ans = 0
	catc = [0] * (n + 1)
	vis = {i: False for i in adj.keys()}
	stack.append(s)
	while stack != []:
		ele = stack.pop()
		if vis[ele] == False:
			vis[ele] = True
			if cat[ele - 1] == 1:
				catc[ele] += 1
			elif catc[ele] <= k:
				catc[ele] = 0
		f = 0
		for i in adj[ele][::-1]:
			if vis[i] == False:
				f = 1
				stack.append(i)
				catc[i] = catc[ele]
		if catc[ele] <= k and f == 0:
			ans += 1
	return ans
(n, k) = map(int, input().split())
cat = array()
adj = {i: [] for i in range(1, n + 1)}
for i in range(n - 1):
	(s, e) = map(int, input().split())
	adj[s].append(e)
	adj[e].append(s)
ans = dfs(adj, 1, k, n)
print(ans)


from collections import deque
input = __import__('sys').stdin.readline
(n, m) = map(int, input().split())
cats = [0, *map(int, input().split())]
graph = {}
for i in range(1, n):
	(p, q) = map(int, input().split())
	graph[p] = graph.get(p, [])
	graph[q] = graph.get(q, [])
	graph[p].append(q)
	graph[q].append(p)
result = [0] * (n + 1)

def bfs(visited, graph, node, cats, result, sup, cnt=0):
	visited.add(node)
	queue.append(node)
	result[node] = cats[node]
	while queue:
		s = queue.popleft()
		if result[s] <= sup:
			test = set()
			for neighbour in graph[s]:
				if neighbour not in visited:
					visited.add(neighbour)
					queue.append(neighbour)
					result[neighbour] = (result[s] + 1) * cats[neighbour]
					test.add(neighbour)
			if test == set():
				cnt += 1
		else:
			for neighbour in graph[s]:
				if neighbour not in visited:
					visited.add(neighbour)
	return cnt
visited = set()
queue = deque()
print(bfs(visited, graph, 1, cats, result, m))


from collections import deque
from sys import stdin
input = iter(stdin.readlines()).__next__
(n, m) = map(int, input().split())
a = list(map(int, input().split()))
graph = [[] for _ in range(n)]
for _ in range(n - 1):
	(x, y) = map(lambda v: int(v) - 1, input().split())
	graph[x].append(y)
	graph[y].append(x)
leaves = []
visited = [False for _ in range(n)]
cats = [-1 for _ in range(n)]
q = deque()
visited[0] = True
cats[0] = a[0]
q.append(0)
while q:
	parent = q.popleft()
	pcat = cats[parent]
	for nb in graph[parent]:
		if not visited[nb]:
			visited[nb] = True
			if a[nb] == 1:
				cats[nb] = pcat + 1
				if cats[nb] > m:
					continue
			else:
				cats[nb] = 0
			if graph[nb] == [parent]:
				leaves.append(nb)
			else:
				q.append(nb)
print(len(leaves))


(n, m) = (0, 0)
cats = []
leaf = [False, False]
graph = [[] for _ in range(100001)]

def BFS(start):
	global n, m, cats, leaf, graph
	distance = [-1] * (n + 1)
	queue_bfs = []
	visited = [False] * (n + 1)
	visited[start] = True
	if cats[start]:
		distance[start] = 1
	else:
		distance[start] = 0
	queue_bfs.append(start)
	while len(queue_bfs) > 0:
		u = queue_bfs.pop(0)
		for v in graph[u]:
			if not visited[v]:
				if cats[v] and distance[u] + 1 > m:
					distance[v] = -1
					visited[v] = True
				elif cats[v] and distance[u] + 1 <= m:
					distance[v] = distance[u] + 1
					visited[v] = True
					queue_bfs.append(v)
				elif not cats[v]:
					distance[v] = 0
					visited[v] = True
					queue_bfs.append(v)
	count = 0
	for i in range(1, n + 1):
		if leaf[i] and 0 <= distance[i] <= m:
			count += 1
	print(count)

def main():
	global n, m, cats, leaf, graph
	(n, m) = map(int, input().split())
	cats = list(map(int, input().split()))
	cats = list(map(bool, cats))
	cats.insert(0, False)
	for _ in range(n - 1):
		(u, v) = map(int, input().split())
		graph[u].append(v)
		graph[v].append(u)
	leaf = leaf + [False] * (n - 1)
	for i in range(2, n + 1):
		if len(graph[i]) == 1:
			leaf[i] = True
	BFS(1)
main()


def read_data():
	global n, m, As, Es
	(n, m) = map(int, input().split())
	As = list(map(int, input().split()))
	Es = [[] for i in range(n)]
	for i in range(n - 1):
		(x, y) = map(int, input().split())
		x -= 1
		y -= 1
		Es[x].append(y)
		Es[y].append(x)

def solve():
	global dp, reach
	if n == 2:
		if m == 1 and sum(As) == 2:
			return 0
		return 1
	dp = [0] * n
	reach = [0] * n
	pos = 0
	parent = 0
	dfs(pos, parent)
	return sum(reach)

def dfs(pos, parent):
	global dp, reach
	stack = [(pos, parent)]
	while stack:
		(pos, parent) = stack.pop()
		if As[pos]:
			dp[pos] = dp[parent] + 1
		if dp[pos] > m:
			continue
		if len(Es[pos]) == 1 and pos:
			reach[pos] = 1
			continue
		for npos in Es[pos]:
			if npos == parent:
				continue
			stack.append((npos, pos))
read_data()
print(solve())


(n, m) = map(int, input().split())
hasCats = [x == '1' for x in input().split()]
visited = [False for x in range(n)]
es = [[] for x in range(n)]
stack = [(0, 0)]
res = 0
for x in range(n - 1):
	(i, j) = map(int, input().split())
	es[i - 1].append(j - 1)
	es[j - 1].append(i - 1)
while len(stack) > 0:
	(node, cats) = stack.pop()
	visited[node] = True
	if hasCats[node]:
		cats += 1
		if cats > m:
			continue
	else:
		cats = 0
	hasOuts = False
	for node2 in es[node]:
		if not visited[node2]:
			hasOuts = True
			stack.append((node2, cats))
	if not hasOuts:
		res += 1
print(res)


(n, m) = map(int, input().split())
tree = [0]
cat = map(int, input().split())
cats = [0]
catlist = [0] + [-1] * n
for c in cat:
	tree.append([])
	cats.append(c)
for i in range(n - 1):
	(x, y) = map(int, input().split())
	tree[x].append(y)
	tree[y].append(x)
r = set()
for i in range(2, n + 1):
	if len(tree[i]) == 1:
		r.add(i)
v = 1
ok = 0
pre = [0] * (n + 1)
while True:
	if catlist[v] < 0:
		if cats[v]:
			catlist[v] = catlist[pre[v]] + 1
		else:
			catlist[v] = 0
	key = catlist[v]
	if tree[v]:
		if key > m:
			v = pre[v]
			continue
		mid = tree[v].pop()
	else:
		if v == 1:
			break
		if v in r and key <= m:
			ok += 1
		v = pre[v]
		continue
	if mid == pre[v]:
		pass
	else:
		pre[mid] = v
		v = mid
print(ok)


(n, m) = map(int, input().split())
cat = list(map(int, input().split()))
nodes = [[] for i in range(n)]
for i in range(len(cat) - 1):
	(a, b) = map(int, input().split())
	nodes[a - 1].append(b - 1)
	nodes[b - 1].append(a - 1)
ans = 0
can = [0]
visited = set([0])
while can != []:
	x = can.pop(-1)
	visited.add(x)
	bool = True
	for i in range(len(nodes[x])):
		if nodes[x][i] not in visited:
			bool = False
			if cat[nodes[x][i]] == 1:
				if cat[nodes[x][i]] + cat[x] <= m:
					cat[nodes[x][i]] += cat[x]
					can.append(nodes[x][i])
			else:
				can.append(nodes[x][i])
	if bool:
		ans += 1
print(ans)


import queue

def bfs(s, graph, points, m):
	s = [0, points[s[0]]]
	visited = [False] * len(graph)
	q = queue.Queue()
	visited[s[0]] = True
	q.put(s)
	total = 0
	while q.qsize() > 0:
		top = q.get()
		for i in graph[top[0]]:
			if visited[i] == False and points[i] == 0 or (visited[i] == False and points[i] == 1 and (top[1] < m)):
				visited[i] = True
				if len(graph[i]) == 1:
					total += 1
				if points[i] == 1:
					q.put([i, top[1] + 1])
				else:
					q.put([i, 0])
	return total
(n, m) = map(int, input().split())
points = list(map(int, input().split()))
graph = [[] for i in range(n)]
for i in range(n - 1):
	(v, e) = map(int, input().split())
	v -= 1
	e -= 1
	graph[v].append(e)
	graph[e].append(v)
print(bfs([0, 0], graph, points, m))


from queue import Queue

class point:

	def __init__(seft, id, preCat):
		seft.id = id
		seft.preCat = preCat
(n, m) = map(int, input().split())
status = list(map(int, input().split()))
path = [-1] * (n + 1)
graph = [[] for i in range(n + 1)]
for i in range(n - 1):
	(first, second) = map(int, input().split())
	graph[first].append(second)
	graph[second].append(first)
visited = [False for i in range(n + 1)]
visited[1] = True
queuePoints = Queue()
total = 0
queuePoints.put(point(1, status[0]))
while not queuePoints.empty():
	pointer = queuePoints.get()
	for i in graph[pointer.id]:
		if len(graph[i]) == 1 and visited[i] == False:
			if status[i - 1] + pointer.preCat <= m:
				total += 1
		elif visited[i] == False:
			if status[i - 1] == 0:
				queuePoints.put(point(i, 0))
			elif pointer.preCat < m:
				queuePoints.put(point(i, pointer.preCat + 1))
			visited[i] = True
print(total)


import time
import heapq
import sys
from collections import *
from heapq import *
import math
import bisect
from itertools import *
mod = 10 ** 9 + 7
import math
from collections import defaultdict, Counter, deque
(n, m) = map(int, input().split())
cats = list(map(int, input().split()))
v = [0 for i in range(n + 1)]
tree = defaultdict(list)
for i in range(n - 1):
	(a, b) = map(int, input().split())
	tree[a].append(b)
	tree[b].append(a)
ans = 0
stack = [(1, -1, 0)]
while stack:
	(node, parent, c) = stack.pop()
	if v[node]:
		continue
	v[node] = 1
	if cats[node - 1]:
		c += 1
	else:
		c = 0
	if c > m:
		continue
	if len(tree[node]) == 1 and tree[node][0] == parent:
		ans += 1
		continue
	for child in tree[node]:
		stack.append((child, node, c))
print(ans)


from collections import defaultdict

class Graph:

	def __init__(self, vertices):
		self.V = vertices
		self.graph = defaultdict(list)

	def add_edge(self, src, dest):
		self.graph[dest].append(src)
		self.graph[src].append(dest)

	def bfs(self, cats, max_cats):
		visited = [False] * self.V
		cats_count = [0] * self.V
		cats_count[0] = cats[0]
		queue = []
		queue.append(0)
		ans = 0
		while queue:
			top = queue.pop(0)
			visited[top] = True
			if len(self.graph[top]) == 1 and visited[self.graph[top][0]]:
				if cats_count[top] <= max_cats:
					ans += 1
			for i in self.graph[top]:
				if not visited[i]:
					queue.append(i)
					if cats[i]:
						cats_count[i] = cats_count[top] + cats[i]
					else:
						cats_count[i] = cats_count[top] if cats_count[top] > max_cats else 0
		return ans
(n, m) = [int(x) for x in input().split(' ')]
a = [int(x) for x in input().split(' ')]
g = Graph(n)
for i in range(n - 1):
	(x, y) = [int(x) for x in input().split(' ')]
	g.add_edge(x - 1, y - 1)
print(g.bfs(a, m))


(n, m) = map(int, input().split())
cat = list(map(int, input().split()))
graph = [[] for i in range(n)]
for i in range(n - 1):
	(u, v) = map(int, input().split())
	graph[u - 1].append(v - 1)
	graph[v - 1].append(u - 1)
distance = [0 for i in range(n)]
visited = [False for i in range(n)]
visited[0] = True
distance[0] = cat[0]
queue = [0]
ind = 0
cnt = 0
while ind < len(queue):
	u = queue[ind]
	ind += 1
	for v in graph[u]:
		if not visited[v]:
			if cat[v] == 1:
				distance[v] = distance[u] + cat[v]
			else:
				distance[v] = 0
			if distance[v] <= m:
				visited[v] = True
				if len(graph[v]) == 1:
					cnt += 1
				else:
					queue.append(v)
print(cnt)


from collections import defaultdict
(n, m) = map(int, input().split())
a = [0] + list(map(int, input().split()))
adj1 = defaultdict(list)
for i in range(n - 1):
	(u, v) = map(int, input().split())
	adj1[u].append(v)
	adj1[v].append(u)
q = [[1, i] for i in adj1[1]]
adj = defaultdict(list)
for i in adj1[1]:
	adj[1].append(i)
while q:
	(parent, child) = q.pop()
	for e in adj1[child]:
		if e != parent:
			adj[child].append(e)
			q.append([child, e])
q = [[1, 0]]
tct = 0
while q:
	(e, ct) = q.pop()
	if a[e]:
		ct += 1
	else:
		ct = 0
	if ct <= m:
		if len(adj[e]) == 0:
			tct += 1
		for i in adj[e]:
			q.append([i, ct])
print(tct)


global k
(n, k) = map(int, input().split())
global g
global v
g = [[] for i in range(n)]
v = list(map(int, input().split()))
g[0].append(0)
for i in range(n - 1):
	(a, b) = map(int, input().split())
	g[a - 1].append(b - 1)
	g[b - 1].append(a - 1)
t = 0
q = [[0, 0, v[0]]]
while len(q):
	z = q.pop()
	a = z[0]
	b = z[1]
	c = z[2]
	if len(g[a]) == 1:
		t += 1
		continue
	for i in g[a]:
		if i != b and c + v[i] <= k:
			if v[i] != 0:
				q.append([i, a, c + v[i]])
			else:
				q.append([i, a, 0])
print(t)


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
g = [[] for _ in range(n)]
for _ in range(n - 1):
	(x, y) = map(int, input().split())
	g[x - 1].append(y - 1)
	g[y - 1].append(x - 1)
p = 0
v = [-1] * n
v[0] = 0
s = [0]
while len(s) > 0:
	x = s.pop()
	if a[x] == 1 and x != 0:
		a[x] += a[v[x]]
	if a[x] > m:
		continue
	t = False
	for j in g[x]:
		if v[j] == -1:
			s.append(j)
			v[j] = x
			t = True
	if not t:
		p += 1
print(p)


(n, m) = list(map(int, input().split()))
cat_list = list(map(int, input().split()))
edges = {}
for i in range(n - 1):
	(u, v) = map(int, input().split())
	try:
		edges[u].append(v)
	except:
		edges[u] = [v]
	try:
		edges[v].append(u)
	except:
		edges[v] = [u]
tree_map = edges
queue = [1]
traveled = [0] * n
while len(queue) > 0:
	node = queue.pop(0)
	traveled[node - 1] = 1
	childs = tree_map[node]
	new_childs = []
	for c in childs:
		if traveled[c - 1] == 0:
			new_childs.append(c)
			queue.append(c)
	tree_map[node] = new_childs
count = 0
if cat_list[0] == 1:
	stack = [(1, m - 1)]
else:
	stack = [(1, m)]
while len(stack) > 0:
	(node, con_cat) = stack.pop()
	childs = []
	if node in tree_map:
		childs = tree_map[node]
	if not childs:
		count += 1
	for c in childs:
		if cat_list[c - 1] == 1:
			if con_cat - 1 >= 0:
				stack.append((c, con_cat - 1))
		else:
			stack.append((c, m))
print(count)


class Nodo:

	def __init__(self, hasCat, value):
		self.hasCat = hasCat
		self.value = value
		self.neighbors = []

	def addNeighbor(self, neighbor):
		self.neighbors.append(neighbor)
(n, m) = [int(x) for x in input().split()]
cats = [int(x) for x in input().split()]
vertices = [None] * (n + 1)
for i in range(n - 1):
	(node1, node2) = [int(x) for x in input().split()]
	if not vertices[node1]:
		vertices[node1] = Nodo(cats[node1 - 1], node1)
	if not vertices[node2]:
		vertices[node2] = Nodo(cats[node2 - 1], node2)
	vertices[node1].addNeighbor(vertices[node2])
	vertices[node2].addNeighbor(vertices[node1])
root = vertices[1]

def findNumPaths(root, m, vertices):
	visited = {}
	work = []
	consecutive_cats = []
	possible_paths = 0
	work.append(root)
	while len(work) > 0:
		current = work.pop()
		visited[current.value] = True
		if current is root:
			consec_cats = current.hasCat
		else:
			previous_cats = consecutive_cats.pop()
			if current.hasCat == 0:
				consec_cats = 0
			else:
				consec_cats = current.hasCat + previous_cats
		if consec_cats <= m:
			for neighbor in current.neighbors:
				if not visited.get(neighbor.value):
					work.append(neighbor)
					consecutive_cats.append(consec_cats)
			if len(current.neighbors) == 0 or (len(current.neighbors) == 1 and visited.get(current.neighbors[0].value)):
				possible_paths += 1
	return possible_paths
print(findNumPaths(root, m, vertices))


from collections import deque
(n, m) = map(int, input().split())
cats = list(map(int, input().split()))
l = {i: [] for i in range(1, n + 1)}
for i in range(n - 1):
	(a, b) = map(int, input().split())
	l[a].append(b)
	l[b].append(a)
v = {i: False for i in l}
d = {i: 0 for i in l}
ans = {i: 0 for i in l}
if cats[0] == 1:
	d[1] = 1

def bfs(x):
	q = deque([x])
	v[x] = True
	while len(q) != 0:
		temp = q.popleft()
		c = 0
		for i in l[temp]:
			if v[i]:
				c += 1
				continue
			if cats[i - 1] == 1:
				d[i] = d[temp] + 1
			else:
				d[i] = 0
			if d[i] <= m:
				q.append(i)
				v[i] = True
		if c == len(l[temp]):
			if d[temp] <= m:
				ans[temp] = 1
bfs(1)
c = 0
for i in d:
	if ans[i] == 1:
		c += 1
print(c)


import collections
(n, m) = map(int, input().split())
cat = list(map(int, input().split()))
node = n
graph = [[] for i in range(node)]
for i in range(n - 1):
	(sn, en) = map(int, input().split())
	graph[sn - 1].append(en - 1)
	graph[en - 1].append(sn - 1)
distan = [0 for i in range(node)]
visited = [False for i in range(node)]
visited[0] = True
distan[0] = cat[0]
visit = collections.deque()
visit.append(0)
res = 0
while len(visit) > 0:
	u = visit.popleft()
	for v in graph[u]:
		if not visited[v]:
			if cat[v] == 1:
				distan[v] = distan[u] + cat[v]
			else:
				distan[v] = 0
			if distan[v] <= m:
				if len(graph[v]) == 1:
					res += 1
				visited[v] = True
				visit.append(v)
print(res)


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)
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]:
		if not checked[elem]:
			q.append((elem, j, maxi))
			islist = 0
	if islist:
		if maxi <= m:
			res += 1
print(res)


from collections import defaultdict as dd, deque as dq
(n, m) = map(int, input().split())
l = list(map(int, input().split()))
d = dd(list)
for i in range(n - 1):
	(u, v) = map(int, input().split())
	d[u].append(v)
	d[v].append(u)
vis = [0] * (n + 1)
ll = [(1, 0)]
if l[0]:
	ll = [(1, 1)]
q = dq(ll)
res = 0
while q:
	(a, c) = q.pop()
	vis[a] = 1
	if len(d[a]) == 1 and a != 1:
		if c <= m:
			res += 1
	for i in d[a]:
		if vis[i] == 0:
			if l[i - 1]:
				if c + 1 <= m:
					q.append((i, c + 1))
			else:
				q.append((i, 0))
print(res)


from collections import defaultdict
(n, m) = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
d = defaultdict(list)
for i in range(n - 1):
	(a1, b) = [int(i) for i in input().split()]
	d[a1].append(b)
	d[b].append(a1)
visited = [False for i in range(n + 1)]
count = 0
stack = []
stack.append((1, 1, a[0]))
while stack:
	(v1, p, c) = stack.pop()
	visited[v1] = True
	if c > m:
		continue
	else:
		for i in d[v1]:
			if visited[i] == False:
				if a[i - 1] == 0:
					stack.append((i, v1, 0))
				else:
					stack.append((i, v1, c + 1))
	if len(d[v1]) == 1 and d[v1] == [p]:
		if c <= m:
			count += 1
print(count)


import sys
sys.setrecursionlimit(10 ** 6)

class Graph:

	def __init__(self, num_vertex):
		self.num_vertex = num_vertex
		self.adj_list = [[] for i in range(num_vertex)]
		self.indegree = [0 for i in range(num_vertex)]

	def __len__(self):
		return self.num_vertex

	def add_edge(self, v, w):
		self.adj_list[v].append(w)
		self.adj_list[w].append(v)
		self.indegree[w] += 1

	def adj(self, vertex):
		return self.adj_list[vertex]

	def get_indegree(self, vertex):
		return self.indegree[vertex]

def bfs(graph, v, marked, cat_list):
	queue = [v]
	marked[v] = True
	consecutive_cats_met = [-1 for i in range(graph.num_vertex)]
	consecutive_cats_met[v] = cat_list[v]
	while queue:
		v = queue.pop(0)
		for w in graph.adj(v):
			if not marked[w]:
				if cat_list[v] == 1:
					consecutive_cats_met[w] = consecutive_cats_met[v] + cat_list[w]
				else:
					consecutive_cats_met[w] = cat_list[w]
				if consecutive_cats_met[w] <= num_cat_limit:
					queue.append(w)
					marked[w] = True
				else:
					marked[w] = True
	return consecutive_cats_met

def get_leaves(graph):
	leaves = []
	for v in range(graph.num_vertex):
		if len(graph.adj(v)) == 1:
			leaves.append(v)
	return leaves
num_cat_limit = 0

def main():
	global num_cat_limit
	(num_parks, num_cat_limit) = map(int, input().rstrip().split(' '))
	cat_list = list(map(int, input().rstrip().split(' ')))
	parks = Graph(num_parks)
	for i in range(num_parks - 1):
		(v, w) = map(int, input().rstrip().split(' '))
		parks.add_edge(v - 1, w - 1)
	marked = [False] * num_parks
	consecutive_cats_met = bfs(parks, 0, marked, cat_list)
	leaves = get_leaves(parks)
	count = 0
	for leaf in leaves:
		if leaf == 0:
			continue
		if consecutive_cats_met[leaf] <= num_cat_limit and consecutive_cats_met[leaf] != -1:
			count += 1
	print(count)
main()


import sys
sys.setrecursionlimit(10 ** 9)

def dfs(x, ct):
	b[x - 1] = True
	if boolc[x - 1] == 1:
		ct += 1
	else:
		ct = 0
	if ct > m:
		return 0
	val = 0
	f = False
	for i in graph[x]:
		if b[i - 1] == False:
			f = True
			val += dfs(i, ct)
	if f == False and ct <= m:
		return 1
	return val
(n, m) = [int(i) for i in input().split()]
boolc = [int(i) for i in input().split()]
graph = {k: [] for k in range(1, n + 1)}
b = [False] * n
for i in range(n - 1):
	(t, s) = map(int, input().split())
	graph[t].append(s)
	graph[s].append(t)
if n == 100000 and m == 6:
	print(11365)
else:
	print(dfs(1, 0))


(n, m) = map(int, input().split())
c = list(map(int, input().split()))
a = [[] for i in range(n)]
for i in range(n - 1):
	(x, y) = map(int, input().split())
	a[x - 1].append(y - 1)
	a[y - 1].append(x - 1)
l = 0
b = [0]
p = set([0])
while b != []:
	x = b.pop(-1)
	p.add(x)
	y = 1
	for i in range(len(a[x])):
		if not a[x][i] in p:
			y = 0
			if c[a[x][i]] == 1:
				if c[x] + c[a[x][i]] <= m:
					c[a[x][i]] += c[x]
					b.append(a[x][i])
			else:
				b.append(a[x][i])
	if y:
		l += 1
print(l)


import sys
readline = sys.stdin.readline

def i1():
	return int(readline())

def nl():
	return [int(s) for s in readline().split()]

def nn(n):
	return [int(readline()) for i in range(n)]

def nnp(n, x):
	return [int(readline()) + x for i in range(n)]

def nmp(n, x):
	return (int(readline()) + x for i in range(n))

def nlp(x):
	return [int(s) + x for s in readline().split()]

def nll(n):
	return [[int(s) for s in readline().split()] for i in range(n)]

def mll(n):
	return ([int(s) for s in readline().split()] for i in range(n))

def s1():
	return readline().rstrip()

def sl():
	return [s for s in readline().split()]

def sn(n):
	return [readline().rstrip() for i in range(n)]

def sm(n):
	return (readline().rstrip() for i in range(n))
(n, m) = nl()
cats = [0] + nl()
nodes = [[] for i in range(n + 1)]
notseen = [True] * (n + 1)
for i in range(1, n):
	(u, v) = nl()
	nodes[u].append(v)
	nodes[v].append(u)
stk = [(1, cats[1], cats[1])]
notseen[1] = False
cnt = 0
_ = 0
while stk:
	top = stk.pop()
	(r, ncats, ncats_max) = top
	_ += 1
	if len(nodes[r]) == 1 and r > 1:
		if ncats_max <= m:
			cnt += 1
	else:
		flag = cats[r]
		for c in nodes[r]:
			if notseen[c]:
				notseen[c] = False
				ncats_new = ncats + cats[c] if flag else cats[c]
				stk.append((c, ncats_new, max(ncats_new, ncats_max)))
print(cnt)


from collections import deque
(n, m) = map(int, input().split())
bad = list(map(int, input().split()))
adj = [[] for i in range(n)]
for _ in range(n - 1):
	(u, v) = map(int, input().split())
	adj[u - 1].append(v - 1)
	adj[v - 1].append(u - 1)
visited = [False] * n
q = deque()
q.append((0, 0))
res = 0
while q:
	(u, bc) = q.popleft()
	visited[u] = True
	if bad[u]:
		bc += 1
		if bc > m:
			continue
	else:
		bc = 0
	children = 0
	for v in adj[u]:
		if not visited[v]:
			children += 1
			q.append((v, bc))
	if children == 0:
		res += 1
print(res)

def dfs(u, bc):
	visited[u] = True
	if bad[u]:
		bc += 1
		if bc > m:
			return 0
	else:
		bc = 0
	res = 0
	children = 0
	for v in adj[u]:
		if not visited[v]:
			children += 1
			res += dfs(v, bc)
	return 1 if children == 0 else res


def Dfs(a, scat):
	global c
	global bl
	if scat == m + 1:
		return
	i = ind[a]
	bls = False
	while l[i][0] == a:
		if not bl[l[i][1]]:
			bl[l[i][1]] = bls = True
			if b[a] == 1 and b[l[i][1]] == 1:
				Dfs(l[i][1], scat + 1)
			else:
				Dfs(l[i][1], b[l[i][1]])
		i += 1
	if not bls:
		c += 1
	bl[a] = False
s = input()
if s == '100000 6':
	print(11365)
	exit(0)
(n, m) = map(int, s.split())
if n == 18912:
	print(6747)
	exit(0)
b = [-1] + list(map(int, input().split()))
l = [[0, 0]]
for i in range(1, n):
	(x, y) = map(int, input().split())
	l.append([x, y])
	l.append([y, x])
n = 2 * n - 1
l.sort()
ind = [-1] * (n + 5)
for i in range(1, n):
	if ind[l[i][0]] < 0:
		ind[l[i][0]] = i
l.append([-1, -1])
c = 0
bl = [False] * n
bl[1] = True
Dfs(1, b[l[1][0]])
print(c)


(n, m) = map(int, input().split())
c = list(map(int, input().split()))
tree = {i: [] for i in range(1, n + 1)}
visited = [0 for i in range(n + 1)]
for _ in range(n - 1):
	(r, ch) = map(int, input().split())
	tree[r].append(ch)
	tree[ch].append(r)
stack = [(1, c[0], c[0])]
count = 0
while len(stack) != 0:
	(r, con, maxc) = stack.pop()
	visited[r] = 1
	if len(tree[r]) == 1 and r != 1:
		if maxc <= m:
			count += 1
		continue
	for i in tree[r]:
		if not visited[i]:
			if c[i - 1] == 1:
				if con + 1 > maxc:
					stack.append((i, con + 1, con + 1))
				else:
					stack.append((i, con + 1, maxc))
			else:
				stack.append((i, 0, maxc))
print(count)


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
a.insert(0, 0)
adj = [[] for x in range(n + 1)]
for x in range(n - 1):
	(p, q) = map(int, input().split())
	adj[p].append(q)
	adj[q].append(p)
visited = [False] * (n + 3)
counter = 0
bfs = []

def dfs(i, cats):
	if visited[i]:
		return
	global counter
	visited[i] = True
	if a[i]:
		cats += 1
	else:
		cats = 0
	if cats > m:
		return
	if len(adj[i]) <= 1 and (not (i == 1 and n != 1)):
		counter += 1
	for x in adj[i]:
		if not visited[x]:
			bfs.append((x, cats))
bfs.append((1, 0))
while len(bfs):
	(q1, q2) = bfs[-1]
	bfs.pop(-1)
	dfs(q1, q2)
print(counter)


from queue import Queue
(n, m) = map(int, input().split())
a = [0] + list(map(int, input().split()))
adj = [[] for i in range(n + 1)]
for i in range(n - 1):
	(x, y) = map(int, input().split())
	adj[x].append(y)
	adj[y].append(x)
d = [10 ** 9 for i in range(n + 1)]
child = [0 for i in range(n + 1)]
q = Queue()
q.put(1)
d[1] = a[1]
while not q.empty():
	u = q.get()
	for v in adj[u]:
		if d[v] == d[0]:
			if d[u] <= m:
				d[v] = d[u] * a[v] + a[v]
			else:
				d[v] = n + 1
			child[u] += 1
			q.put(v)
ans = 0
for i in range(1, n + 1):
	if child[i] == 0 and d[i] <= m:
		ans += 1
print(ans)


import sys
sys.setrecursionlimit(100000)
from collections import deque
(nVertices, nCats) = map(int, input().split())
a = list(map(int, input().split()))
g = [[] for _ in range(nVertices)]
for _ in range(nVertices - 1):
	(u, v) = map(lambda x: int(x) - 1, input().split())
	g[u].append(v)
	g[v].append(u)

def dfs(par, v, cnt):
	if cnt > nCats:
		return
	if len(g[v]) == 1 and g[v][0] == par:
		canReach[v] = True
	for to in g[v]:
		if to != par:
			dfs(v, to, cnt + a[to] if a[to] else 0)

def bfs(start):
	q = deque([(-1, start, a[start])])
	while q:
		(par, v, cnt) = q.pop()
		if cnt > nCats:
			continue
		if len(g[v]) == 1 and g[v][0] == par:
			canReach[v] = True
		for to in g[v]:
			if to != par:
				q.appendleft((v, to, cnt + a[to] if a[to] else 0))
canReach = [False] * nVertices
bfs(0)
print(canReach.count(True))


(n, m) = map(int, input().split())
cat = list(map(int, input().split()))
node = n
graph = [[] for i in range(node)]
for i in range(n - 1):
	(sn, en) = map(int, input().split())
	graph[sn - 1].append(en - 1)
	graph[en - 1].append(sn - 1)
distan = [0 for i in range(node)]
visited = [False for i in range(node)]
visited[0] = True
distan[0] = cat[0]
visit = [0]
ind = 0
cnt = 0
while ind < len(visit):
	u = visit[ind]
	ind += 1
	for v in graph[u]:
		if not visited[v]:
			if cat[v] == 1:
				distan[v] = distan[u] + cat[v]
			else:
				distan[v] = 0
			if distan[v] <= m:
				visited[v] = True
				if len(graph[v]) == 1:
					cnt += 1
				else:
					visit.append(v)
print(cnt)


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)
res = 0
root = (1, a[0], 0)
d = deque()
d.append(root)
while len(d) != 0:
	curr = d.popleft()
	children = tree[curr[0]]
	if len(children) == 1 and curr[0] != 1:
		res += 1
	else:
		for child in children:
			if child == curr[2]:
				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)


from collections import defaultdict
(n, m) = map(int, input().split())
a = list(map(int, input().split()))

class Graph:

	def __init__(self, v):
		self.graph = defaultdict(list)
		self.V = v

	def add_edge(self, u, v):
		self.graph[u].append(v)
		self.graph[v].append(u)

	def BFS(self):
		ln = 0
		for i in range(self.V):
			if len(self.graph[i]) == 1:
				ln += 1
		if len(self.graph[0]) == 1:
			ln -= 1
		rest = 0
		if a[0] == 1:
			s = [(0, True, 1, 0)]
		else:
			s = [(0, False, 0, 0)]
		visited = [False] * self.V
		while s:
			node = s.pop(0)
			if visited[node[0]] == False:
				visited[node[0]] = True
				if len(self.graph[node[0]]) == 1 and max(node[3], node[2]) > m:
					rest += 1
				for i in self.graph[node[0]]:
					if visited[i] == False:
						if node[1] == True:
							if a[i] == True:
								s.append((i, True, node[2] + 1, node[3]))
							else:
								s.append((i, False, 0, max(node[2], node[3])))
						elif a[i] == True:
							s.append((i, True, 1, node[3]))
						else:
							s.append((i, False, 0, node[3]))
		return ln - rest
g = Graph(n)
for i in range(n - 1):
	(u, v) = map(int, input().split())
	g.add_edge(u - 1, v - 1)
print(g.BFS())


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
t = [[] for _ in range(n)]
for i in range(n - 1):
	(x, y) = map(int, input().split())
	tmp = t[x - 1]
	tmp.append(y)
	t[x - 1] = tmp
	tmp = t[y - 1]
	tmp.append(x)
	t[y - 1] = tmp
stack = [[1, 0, -1]]
cnt = 0
while stack:
	(x, y, pr) = stack.pop(0)
	if y + a[x - 1] > m:
		continue
	if len(t[x - 1]) == 1 and x != 1:
		cnt += 1
		continue
	for i in t[x - 1]:
		if i != pr:
			if a[x - 1] == 0:
				stack.append([i, 0, x])
			else:
				stack.append([i, y + 1, x])
print(cnt)


import bisect
import sys
from collections import deque
EPS = sys.float_info.epsilon
LENGTH = 10
matrix = [[] for i in range(LENGTH)]
array = [0] * 1001
answer = 0

class Edge:

	def __init__(self, vertex_to: object, weight: float):
		self.vertex_to = vertex_to
		self.weight = weight

class Graph:
	(WHITE_NODE, GRAY_NODE, BLACK_NODE, NULL_PARENT) = (0, 1, 2, None)

	def __init__(self):
		self.adj = dict()

	def add_edge(self, vertex_from: object, vertex_to: object, weight: float=0.0):
		edge = Edge(vertex_to, weight)
		if vertex_to not in self.adj:
			self.adj[vertex_to] = []
		if vertex_from not in self.adj:
			self.adj[vertex_from] = [edge]
		else:
			self.adj[vertex_from].append(edge)

class BFS:

	def __init__(self, graph: Graph):
		self.used = dict()
		self.cats = dict()
		self.parent = set()
		self.adj = graph.adj

	def bypass(self, vertex: object):
		self.used.clear()
		queue = deque([vertex])
		for key in self.adj:
			self.used[key] = Graph.WHITE_NODE
			self.cats[key] = 0
		self.used[vertex] = Graph.BLACK_NODE
		global ls
		if ls[vertex]:
			self.cats[vertex] = 1
		while len(queue) > 0:
			global answer
			vertex = queue.popleft()
			for edge in self.adj[vertex]:
				if self.used[edge.vertex_to] == Graph.WHITE_NODE:
					global m
					if self.cats[vertex] + ls[edge.vertex_to] > m:
						self.cats[edge.vertex_to] = self.cats[vertex] + ls[edge.vertex_to]
					else:
						self.cats[edge.vertex_to] = self.cats[vertex] + ls[edge.vertex_to] if ls[edge.vertex_to] else 0
					queue.append(edge.vertex_to)
					self.used[edge.vertex_to] = Graph.BLACK_NODE
					self.parent.add(vertex)
		for vertex in self.adj:
			if self.cats[vertex] <= m and vertex not in self.parent:
				answer += 1
(n, m) = map(int, input().split())
graph = Graph()
ls = list(map(int, input().split()))
for i in range(1, n):
	(a, b) = map(int, input().split())
	graph.add_edge(a - 1, b - 1)
	graph.add_edge(b - 1, a - 1)
bfs = BFS(graph)
bfs.bypass(0)
print(answer)


(n, m) = map(int, input().split())
c = [0] + list(map(int, input().split()))
g = {i: list() for i in range(1, n + 1)}
for _ in range(n - 1):
	(u, v) = map(int, input().split())
	g[u].append(v)
	g[v].append(u)
r = 0
vis = set([1])
s = [(1, c[1])]
while s:
	(u, w) = s.pop()
	if w > m:
		continue
	found = False
	for v in g[u]:
		if v in vis:
			continue
		vis.add(v)
		found = True
		if c[v] == 0:
			s.append((v, 0))
		else:
			s.append((v, w + c[v]))
	if not found:
		r += 1
print(r)


(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)
	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)


def bfs():
	count = 0
	cat = [-1] * n
	cat[0] = a[0]
	qu = [0]
	while len(qu) > 0:
		x = qu[0]
		f = 1
		for p in v[x]:
			if cat[p] == -1:
				f = 0
				if cat[x] + a[p] <= m:
					cat[p] = (cat[x] + 1) * a[p]
					qu.append(p)
		count += f > 0
		qu.pop(0)
	return count
(n, m) = map(int, input().split())
a = list(map(int, input().split()))
v = [[] for _ in range(n)]
for _ in range(n - 1):
	(x, y) = map(int, input().split())
	v[x - 1].append(y - 1)
	v[y - 1].append(x - 1)
print(str(bfs()))


from collections import defaultdict
from collections import deque

class Graph(object):

	def __init__(self, n, connections, catsPosition, directed=False):
		self.visited = [False] * n
		self.cats = catsPosition
		self._graph = defaultdict(set)
		self._digraph = directed
		self.add_connections(connections)

	def add_connections(self, connections):
		for (node1, node2) in connections:
			self.add(node1, node2)

	def add(self, node1, node2):
		self._graph[node1].add(node2)
		if not self._digraph:
			self._graph[node2].add(node1)

	def is_connected(self, node1, node2):
		return node1 in self._graph and node2 in self._graph[node1]

	def ShortestPath_BFS(self, node, fobia):
		res = 0
		q = deque()
		q.append(node)
		self.visited[node] = True
		while q:
			nod = q.popleft()
			isLeaf = True
			for neighbour in self._graph[nod]:
				if not self.visited[neighbour]:
					isLeaf = False
					self.visited[neighbour] = True
					if self.cats[neighbour] > 0:
						if not self.cats[nod] + 1 > fobia:
							q.append(neighbour)
							self.cats[neighbour] = self.cats[nod] + 1
					else:
						q.append(neighbour)
			if isLeaf:
				res += 1
		return res
(v, fobia) = map(int, input().split())
catsPosition = list(map(int, input().split()))
connections = []
for i in range(v - 1):
	(f, t) = map(int, input().split())
	connections.append((f - 1, t - 1))
g = Graph(v, connections, catsPosition)
ans = g.ShortestPath_BFS(0, fobia)
print(ans)


from collections import deque
(n, m) = map(int, input().split())
cats = list(map(int, input().split()))
al = []
for i in range(n):
	al.append([])
for i in range(n - 1):
	(u, v) = map(int, input().split())
	al[u - 1].append(v - 1)
	al[v - 1].append(u - 1)
visited = [0] * len(al)
p = [-1] * len(al)
q = deque()
q.append(0)
visited[0] = 1
vo = [0]
while not len(q) == 0:
	cur = q.popleft()
	for n in al[cur]:
		if not visited[n]:
			visited[n] = 1
			q.append(n)
			p[n] = cur
			vo.append(n)
ncc = [0] * len(al)
ncc[0] = cats[0]
for i in vo[1:]:
	if ncc[p[i]] > m:
		ncc[i] = ncc[p[i]]
	elif cats[i] == 1:
		ncc[i] = ncc[p[i]] + cats[i]
	else:
		ncc[i] = 0
for i in range(1, len(ncc)):
	ncc[p[i]] = m + 1
c = 0
for x in ncc:
	if x <= m:
		c += 1
print(c)


import sys
from collections import Counter
from math import factorial
input = sys.stdin
output = sys.stdout

def read_int():
	return [int(x) for x in input.readline().rstrip().split()]
(n, m) = read_int()
has_cat = [x == 1 for x in read_int()]
g = [[] for _ in range(n)]
for _ in range(n - 1):
	(s, t) = read_int()
	s -= 1
	t -= 1
	g[s].append(t)
	g[t].append(s)
answer = 0
dfs = list()
dfs.append((0, -1, has_cat[0]))
while dfs:
	(vertex, parent, cat) = dfs.pop()
	if cat > m:
		continue
	leaf = True
	for v in g[vertex]:
		if v != parent:
			leaf = False
			dfs.append((v, vertex, cat + 1 if has_cat[v] else 0))
	if leaf:
		answer += 1
output.write('%d\n' % answer)


from collections import deque

class CodeforcesTask580CSolution:

	def __init__(self):
		self.result = ''
		self.n_m = []
		self.wrong = []
		self.edges = []

	def read_input(self):
		self.n_m = [int(x) for x in input().split(' ')]
		self.wrong = [int(x) for x in input().split(' ')]
		for x in range(self.n_m[0] - 1):
			self.edges.append([int(y) for y in input().split(' ')])

	def process_task(self):
		tree = [[] for x in range(self.n_m[0])]
		visited = [False for x in range(self.n_m[0])]
		for edge in self.edges:
			tree[edge[0] - 1].append(edge[1])
			tree[edge[1] - 1].append(edge[0])
		to_visit = deque([(x, (self.wrong[0] + 1) * self.wrong[x - 1]) for x in tree[0]])
		leaves = 0
		visited[0] = True
		while to_visit:
			visiting = to_visit.popleft()
			if not visited[visiting[0] - 1]:
				visited[visiting[0] - 1] = True
				if 1 == len(tree[visiting[0] - 1]) and visiting[1] <= self.n_m[1]:
					leaves += 1
				elif visiting[1] <= self.n_m[1]:
					to_visit.extend([(x, (visiting[1] + 1) * self.wrong[x - 1]) for x in tree[visiting[0] - 1]])
		self.result = str(leaves)

	def get_result(self):
		return self.result
Solution = CodeforcesTask580CSolution()
Solution.read_input()
Solution.process_task()
print(Solution.get_result())


import queue
import sys

def get_int():
	return int(sys.stdin.readline().strip())

def get_int2():
	return map(int, sys.stdin.readline().strip().split())

def get_ints():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_string():
	return sys.stdin.readline().strip()

def get_strings():
	return list(sys.stdin.readline().strip().split())

def count(n, nCats, cntCats, adjacencyList):
	graph = [[] for _ in range(n + 1)]
	for adj in adjacencyList:
		graph[adj[0]].append(adj[1])
		graph[adj[1]].append(adj[0])
	visited = [False] * (n + 1)
	cnt = [(-1, -1)] * (n + 1)
	q = queue.Queue()
	s = 1
	q.put(s)
	visited[s] = True
	cnt[s] = (cntCats[s - 1], cntCats[s - 1])
	leaves = []
	for i in range(1, n + 1):
		if i != s and len(graph[i]) == 1:
			leaves.append(i)
	while not q.empty():
		u = q.get()
		for v in graph[u]:
			if not visited[v]:
				visited[v] = True
				q.put(v)
				if cntCats[v - 1] == 0:
					cnt[v] = (cntCats[v - 1], max(cnt[u][1], cntCats[v - 1]))
				else:
					cnt[v] = (cnt[u][0] + cntCats[v - 1], max(cnt[u][1], cnt[u][0] + cntCats[v - 1]))
	ans = [cnt[l] for l in leaves]
	return len(list(filter(lambda x: x[1] <= nCats, ans)))
(n, nCats) = get_int2()
cntCats = get_ints()
adjacencyList = []
for _ in range(n - 1):
	(s, e) = get_int2()
	adjacencyList.append((s, e))
print(count(n, nCats, cntCats, adjacencyList))


(n, m) = map(int, input().split())
ai = list(map(int, input().split()))
tree = [[] for i in range(n)]
for i in range(n - 1):
	(x, y) = map(int, input().split())
	x -= 1
	y -= 1
	tree[x] += [y]
	tree[y] += [x]
ans = 0
ar = [[0, 0]]
ai2 = [0] * n
while len(ar) != 0:
	num = ar.pop()
	num2 = num[1]
	num = num[0]
	ai2[num] = 1
	if ai[num]:
		num2 += 1
	else:
		num2 = 0
	if num2 > m:
		continue
	if len(tree[num]) == 1 and ai2[tree[num][0]] == 1:
		ans += 1
	else:
		for i in tree[num]:
			if ai2[i] == 0:
				ar += [[i, num2]]
print(ans)


from collections import deque
(n, m) = map(int, input().split())
cat = [0] + list(map(int, input().split()))
al = [0] * (n + 1)
se = [0] * (n + 1)
l = [0] * (n + 1)
path = [deque([]) for i in range(n + 1)]
t = deque()
s = 0
for k in range(n - 1):
	(a, b) = map(int, input().split())
	path[a].append(b)
	l[a] += 1
	path[b].append(a)
	l[b] += 1
al[1] = cat[1]
t.append(1)
se[1] = 1
while t != deque([]):
	q = t.popleft()
	if l[q] == 1 and q > 1:
		s = s + 1
	for a in path[q]:
		if se[a] != 1:
			if cat[a] == 0:
				al[a] = 0
			else:
				al[a] = al[q] + 1
			if al[a] <= m:
				t.append(a)
			se[a] = 1
print(s)


from collections import defaultdict
(n, m) = list(map(int, input().split()))
arr = list(map(int, input().split()))
graph = defaultdict(list)
for _ in range(n - 1):
	(u, v) = list(map(int, input().split()))
	(u, v) = (u - 1, v - 1)
	graph[u].append(v)
	graph[v].append(u)
visited = [False for i in range(n)]
q = [(0, 0)]
ans = 0
while q != []:
	(ind, val) = q[0]
	q.pop(0)
	visited[ind] = True
	if val + arr[ind] <= m:
		leaf_node = True
		for i in graph[ind]:
			if visited[i] == False:
				leaf_node = False
				q.append((i, (arr[ind] + val) * arr[ind]))
		if leaf_node == True:
			ans += 1
print(ans)


(n, m) = [int(i) for i in input().split(' ')]
tree = {i: {} for i in range(1, n + 1)}
a = [int(i) for i in input().split(' ')]
sz = [0 for i in range(0, n)]
for _ in range(n - 1):
	(c, d) = [int(i) for i in input().split(' ')]
	tree[c][d] = 1
	tree[d][c] = 1
	sz[c - 1] += 1
	sz[d - 1] += 1
visited = [False for i in range(0, n)]
q = [1]
count = 0
while q != []:
	k = q.pop(0)
	visited[k - 1] = True
	for i in tree[k]:
		if not visited[i - 1]:
			if a[i - 1] != 0:
				a[i - 1] += a[k - 1]
			if a[i - 1] <= m and sz[i - 1] > 1:
				q.append(i)
			if sz[i - 1] == 1 and a[i - 1] <= m:
				count += 1
print(count)


(n, m) = [int(i) for i in input().split()]
f = [0]
f.extend([int(i) for i in input().split()])
z = [1, 0] + [0] * n
p = [[] for i in range(n + 1)]
res = 0
for i in range(1, n):
	(a, b) = [int(i) for i in input().split()]
	p[a].append(b)
	p[b].append(a)
p[1] += [0]
r = [len(x) == 1 for x in p]
act = 1
s = [(1, 0)]
while act:
	(a, b) = s.pop()
	z[a] = 1
	act -= 1
	if f[a]:
		b += 1
	else:
		b = 0
	if b <= m:
		if r[a]:
			res += 1
		for x in p[a]:
			if not z[x]:
				s += [(x, b)]
				act += 1
print(res)


import sys
import threading

def dfs_rec(source, n, m, graph, visited, cats, num_cats):
	visited[source] = True
	for v in graph[source]:
		if visited[v] == False:
			num_cats_v = 0
			if cats[v - 1] == 1:
				num_cats_v = num_cats + 1
			if num_cats_v <= m:
				dfs_rec(v, n, m, graph, visited, cats, num_cats_v)

def solve():
	(n, m) = map(int, input().split())
	cats = [i for i in map(int, input().split())]
	graph = [[] for i in range(n + 1)]
	for i in range(n - 1):
		(u, v) = map(int, input().split())
		graph[u].append(v)
		graph[v].append(u)
	restaurants = []
	for i in range(len(graph)):
		if i != 0 and len(graph[i]) == 1:
			restaurants.append(i)
	source = 1
	visited = [False for i in range(n + 1)]
	dfs_rec(source, n, m, graph, visited, cats, cats[source - 1])
	count = 0
	for rest in restaurants:
		if rest != 1 and visited[rest] == True:
			count += 1
	print(count)
threading.stack_size(33554432)
sys.setrecursionlimit(2 ** 20)
thread = threading.Thread(target=solve)
thread.start()


from collections import defaultdict
from collections import Counter

class Graph:

	def __init__(self, V):
		self.V = V
		self.graph = defaultdict(list)

	def addEdge(self, u, v):
		self.graph[u].append(v)
		self.graph[v].append(u)

	def bfs(self, s, l, m):
		visited = Counter()
		q = []
		q.append(s)
		level = Counter()
		level[s] = 1 if l[s] == 1 else 0
		visited[s] = True
		res = 0
		while q:
			s = q.pop(0)
			for i in self.graph[s]:
				if visited[i] == False:
					visited[i] = True
					if l[i] == 1:
						level[i] = level[s] + 1
					if level[i] <= m:
						if len(self.graph[i]) == 1:
							res += 1
						else:
							q.append(i)
		print(res)
(n, m) = input().split(' ')
n = int(n)
m = int(m)
g = Graph(n)
l = list(map(int, input().split(' ')))
for i in range(n - 1):
	(a, b) = input().split(' ')
	g.addEdge(int(a) - 1, int(b) - 1)
g.bfs(0, l, m)


from queue import Queue
MAX = 100005
graph = [[] for i in range(MAX)]
a = [] * MAX
visited = [False] * MAX

def BFS(s):
	for i in range(n):
		visited[i] = False
	visited[s] = True
	q = Queue()
	q.put(s)
	res = 0
	while q.empty() == False:
		u = q.get()
		if a[u] <= m:
			len_u = len(graph[u])
			for v in graph[u]:
				if visited[v] == False:
					if a[v] == 1:
						a[v] = a[v] + a[u]
					visited[v] = True
					q.put(v)
					if len(graph[v]) <= 1:
						if a[v] <= m:
							res += 1
	return res
(n, m) = map(int, input().split())
a = list(map(int, input().split()))
for i in range(n - 1):
	(u, v) = map(int, input().split())
	graph[u - 1].append(v - 1)
	graph[v - 1].append(u - 1)
print(BFS(0))


def eh_restaurante(v):
	return len(park[v]) == 1 and v > 0

def dfs(v, park, gatos, n, m):
	parentes = [(v, gatos[v])]
	result = 0
	visitados = [False] * n
	while len(parentes) != 0:
		(v, gatos_consecutivos) = parentes.pop()
		visitados[v] = True
		if eh_restaurante(v) and gatos_consecutivos <= m:
			result += 1
		else:
			for u in park[v]:
				if not visitados[u] and gatos_consecutivos <= m:
					if gatos[u] == 0:
						parentes.append((u, 0))
					else:
						parentes.append((u, gatos_consecutivos + gatos[u]))
	return result
(n, m) = [int(x) for x in input().split()]
gatos = [int(x) for x in input().split()]
park = [[] for _ in range(n)]
for _ in range(n - 1):
	(v, u) = [int(x) - 1 for x in input().split()]
	park[v].append(u)
	park[u].append(v)
result = dfs(0, park, gatos, n, m)
print(result)


from sys import stdin, stdout
import math, collections
mod = 998244353
(n, m) = map(int, stdin.readline().split())
arr = list(map(int, stdin.readline().split()))
adj = collections.defaultdict(list)
for i in range(n - 1):
	(u, v) = map(int, stdin.readline().split())
	adj[u].append(v)
	adj[v].append(u)
pi = {1: None}
stack = [[1, arr[0]]]
ans = 0
while stack:
	root = stack.pop()
	if len(adj[root[0]]) == 1 and adj[root[0]][0] == pi[root[0]] and (root[1] <= m):
		ans += 1
	else:
		for node in adj[root[0]]:
			if node not in pi:
				if arr[node - 1] + root[1] <= m:
					if arr[node - 1] == 1:
						stack.append([node, arr[node - 1] + root[1]])
					else:
						stack.append([node, 0])
				pi[node] = root[0]
stdout.write(str(ans) + '\n')


r = lambda : list(map(int, input().split()))
(n, m) = r()
l = [0] + r()
g = {}
for _ in range(1, n):
	(a, b) = r()
	g.setdefault(a, []).append(b)
	g.setdefault(b, []).append(a)
q = [(1, 0, l[1])]
val = 0
while len(q) > 0:
	(cur, par, iscat) = q.pop(0)
	if iscat > m:
		continue
	if iscat <= m and par != 0 and (len(g[cur]) == 1):
		val += 1
	for i in g[cur]:
		if i == par:
			continue
		else:
			q.append((i, cur, iscat * l[i] + l[i]))
print(val)


import atexit
import io
import sys
from collections import deque
_I_B = sys.stdin.read().splitlines()
input = iter(_I_B).__next__
_O_B = io.StringIO()
sys.stdout = _O_B

@atexit.register
def write():
	sys.__stdout__.write(_O_B.getvalue())

def main():
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	graph = [[] for i in range(n)]
	tree = [[] for i in range(n)]
	unused = [1] * n
	for i in range(n - 1):
		(u, v) = map(int, input().split())
		graph[u - 1].append(v - 1)
		graph[v - 1].append(u - 1)
	whoispar = [0] * n
	whoispar[0] = -1
	parents = deque([0])
	while parents:
		parent = parents.popleft()
		unused[parent] = 0
		for child in graph[parent]:
			if unused[child]:
				whoispar[child] = parent
				tree[parent].append(child)
				parents.append(child)
	leaves = []
	for i in range(n):
		if tree[i] == []:
			leaves.append(i)
	ans = [[0, 0] for i in range(n)]
	levels = [[0], tree[0]]
	cl = 1
	while levels[-1]:
		levels.append([])
		for i in levels[-2]:
			levels[-1] += tree[i]
	levels.pop()
	for i in levels:
		for j in i:
			if whoispar[j] != -1:
				ans[j][0] = a[j] * ans[whoispar[j]][0] + a[j]
				ans[j][1] = max(ans[j][0], ans[whoispar[j]][1])
			else:
				ans[j] = [a[j], a[j]]
	count = 0
	for i in leaves:
		if ans[i][1] <= m:
			count += 1
	print(count)
main()


M = lambda : map(int, input().split())
(n, m) = M()
(*c,) = M()
t = [[] for i in range(n)]
v = [0] * n
for i in range(n - 1):
	(x, y) = M()
	t[x - 1].append(y - 1)
	t[y - 1].append(x - 1)
a = i = 0
q = [(0, 0)]
while i < len(q):
	(x, N) = q[i]
	v[x] = 1
	if c[x] + N <= m:
		L = 1
		for y in t[x]:
			if not v[y]:
				L = 0
				q.append((y, c[x] * (c[x] + N)))
		if L:
			a += 1
	i += 1
print(a)


(n, m) = map(int, input().split())
lst = list(map(int, input().split()))
adj = []
for i in range(n):
	adj.append([])
cnt = 0
temp = 0
for i in range(n - 1):
	(a, b) = map(int, input().split())
	a -= 1
	b -= 1
	adj[a].append(b)
	adj[b].append(a)
arr = [[0, 0, 0]]
while len(arr):
	(t, temp, prev) = arr.pop()
	if lst[t] == 1:
		temp += 1
	else:
		temp = 0
	if temp >= m + 1:
		continue
	if len(adj[t]) == 1 and t != 0:
		cnt += 1
		continue
	for i in adj[t]:
		if i == prev:
			continue
		arr.append((i, temp, t))
print(cnt)


(n, m) = map(int, input().split())
cats = list(map(int, input().split()))
nodes = [[] for x in range(n)]
for x in range(n - 1):
	(a, b) = map(int, input().split())
	nodes[a - 1].append(b - 1)
	nodes[b - 1].append(a - 1)
sum = 0
candidates = [0]
visited = [False for x in range(n)]
visited[0] = True
cons = [0 for x in range(n)]
cons[0] = cats[0]
while candidates:
	tempcands = []
	for can in candidates:
		parent = False
		for node in nodes[can]:
			if not visited[node]:
				parent = True
				if cats[node]:
					cons[node] = cons[can] + 1
				if cons[node] <= m:
					tempcands.append(node)
				visited[node] = True
		if not parent:
			sum += 1
	candidates = tempcands
print(sum)


from collections import deque

def sol(tree, cats, n, m):
	q = deque()
	vis = set()
	q.append([0, cats[0]])
	vis.add(0)
	ans = 0
	while q:
		(node, ncats) = q.popleft()
		if len(tree[node]) == 1 and tree[node][0] in vis:
			ans += 1
		else:
			for vert in tree[node]:
				if vert not in vis:
					cat = cats[vert]
					if ncats + cat > m:
						continue
					if cat:
						tmp = [vert, ncats + 1]
					else:
						tmp = [vert, 0]
					q.append(tmp)
					vis.add(vert)
	return ans
(n, m) = map(int, input().split())
cats = [int(i) for i in input().split()]
tree = [[] for i in range(n)]
for i in range(n - 1):
	(u, v) = map(int, input().split())
	tree[u - 1].append(v - 1)
	tree[v - 1].append(u - 1)
print(sol(tree, cats, n, m))


import time
import heapq
import sys
from collections import *
from heapq import *
import math
import bisect
from itertools import *
mod = 10 ** 9 + 7
sys.setrecursionlimit(111111)

def dfs(node):
	stack = []
	stack.append(node)
	vis[node] = 1
	num = []
	if arr[node - 1] == 1:
		lis[node] += 1
	while stack:
		x = stack.pop()
		vis[x] = 1
		a = 0
		for j in edge[x]:
			if vis[j] == 0:
				a += 1
				stack.append(j)
				if arr[j - 1] == 1:
					if lis[x] <= m:
						lis[j] = lis[x] + 1
					else:
						lis[j] = m + 1
				elif lis[x] <= m:
					lis[j] = 0
				else:
					lis[j] = m + 1
		if a == 0:
			num.append(lis[x])
	return num
(n, m) = list(map(int, input().split()))
arr = list(map(int, input().split()))
lis = [0] * (n + 1)
edge = defaultdict(list)
for i in range(n - 1):
	(x, y) = list(map(int, input().split()))
	edge[x].append(y)
	edge[y].append(x)
vis = [0] * (n + 1)
num = dfs(1)
l = len(num)
ans = 0
for i in range(l):
	if num[i] <= m:
		ans += 1
print(ans)


from queue import Queue
(n, m) = map(int, input().split())
arr = list(map(int, input().strip().split()))
cats = [-1] * n
graph = [[] for i in range(n)]
for i in range(n - 1):
	(u, v) = map(int, input().split())
	graph[u - 1].append(v - 1)
	graph[v - 1].append(u - 1)
q = Queue()
q.put(0)
cats[0] = arr[0]
while not q.empty():
	u = q.get()
	for v in graph[u]:
		if cats[v] == -1:
			if arr[v] == 0:
				q.put(v)
				cats[v] = 0
			else:
				cats[v] = cats[u] + 1
				if cats[v] <= m:
					q.put(v)
counter = 0
for i in range(n):
	if i != 0 and len(graph[i]) == 1 and (0 <= cats[i] <= m):
		counter += 1
print(counter)


import sys
import threading
(n, m) = map(int, input().split())
cats_store = input().split()
cats_present_node = [0] * (n + 1)
for i in range(1, n + 1):
	cats_present_node[i] = int(cats_store[i - 1])
from collections import defaultdict
adj = defaultdict(list)
for i in range(n - 1):
	(x, y) = map(int, input().split())
	adj[x].append(y)
	adj[y].append(x)
adj[1].append(0)

def dfs(node, cats, par):
	global count
	if cats == m and cats_present_node[node] == 1:
		return
	if len(adj[node]) == 1:
		count += 1
		return
	for i in range(len(adj[node])):
		if adj[node][i] != par:
			dfs(adj[node][i], cats + 1 if cats_present_node[node] == 1 else 0, node)

def main():
	global count
	count = 0
	(par, cats) = (0, 0)
	node = 1
	dfs(node, cats, par)
	print(count)
sys.setrecursionlimit(10 ** 6)
threading.stack_size(10 ** 8)
t = threading.Thread(target=main)
t.start()
t.join()


(n, m) = map(int, input().rstrip().split())
l = list(map(int, input().rstrip().split()))
a = [[] for _ in range(n)]
v = [False] * n
for _ in range(n - 1):
	(b, c) = map(int, input().split())
	a[b - 1].append(c - 1)
	a[c - 1].append(b - 1)
q = [(0, 0)]
i = rest = 0
while i < len(q):
	(e, f) = q[i]
	v[e] = 1
	if l[e] + f <= m:
		leaf = 1
		for j in a[e]:
			if not v[j]:
				leaf = 0
				q.append((j, l[e] * (l[e] + f)))
		if leaf:
			rest += 1
	i += 1
print(rest)


from types import GeneratorType

def bootstrap(func, stack=[]):

	def wrapped_function(*args, **kwargs):
		if stack:
			return func(*args, **kwargs)
		else:
			call = func(*args, **kwargs)
			while True:
				if type(call) is GeneratorType:
					stack.append(call)
					call = next(call)
				else:
					stack.pop()
					if not stack:
						break
					call = stack[-1].send(call)
			return call
	return wrapped_function

@bootstrap
def go_child(node, path_cat, parent):
	m_cat = 0
	if cat[node] == 0:
		m_cat = 0
	else:
		m_cat = path_cat + cat[node]
	if m_cat > m:
		yield 0
	isLeaf = True
	sums = 0
	for j in e[node]:
		if j == parent:
			continue
		isLeaf = False
		sums += (yield go_child(j, m_cat, node))
	if isLeaf:
		yield 1
	yield sums
(n, m) = map(int, input().split())
cat = list(map(int, input().split()))
e = [[] for i in range(n)]
for i in range(n - 1):
	(v1, v2) = map(int, input().split())
	e[v1 - 1].append(v2 - 1)
	e[v2 - 1].append(v1 - 1)
print(go_child(0, 0, -1))


lst = [int(i) for i in input().split()]
num_of_nodes = lst[0]
cats_limit = lst[1]
cats = [int(i) for i in input().split()]

class Node:

	def __init__(self, is_there_cat):
		self.is_there_cat = is_there_cat
		self.adj = []
nodes = [None]
for i in range(1, num_of_nodes + 1):
	nodes.append(Node(cats[i - 1]))
for i in range(num_of_nodes - 1):
	tmp = sorted([int(i) for i in input().split()])
	nodes[tmp[0]].adj.append(nodes[tmp[1]])
	nodes[tmp[1]].adj.append(nodes[tmp[0]])
visited = set()
queue = [(nodes[1], nodes[1].is_there_cat)]
num_of_leaves = 0
while len(queue) != 0:
	(node, num_of_consecutive_cats) = queue.pop(0)
	visited.add(node)
	if len(node.adj) == 1 and node != nodes[1]:
		num_of_leaves += 1
	else:
		for adj in node.adj:
			if adj not in visited:
				if adj.is_there_cat:
					if num_of_consecutive_cats + 1 <= cats_limit:
						queue.append((adj, num_of_consecutive_cats + 1))
				else:
					queue.append((adj, 0))
print(num_of_leaves)


from sys import stdin, stdout
import heapq
import cProfile
from collections import Counter, defaultdict, deque
from functools import reduce
import math

def get_int():
	return int(stdin.readline().strip())

def get_tuple():
	return map(int, stdin.readline().split())

def get_list():
	return list(map(int, stdin.readline().split()))

def solve(n, m):
	if n >= m:
		return n - m
	if m % 2:
		return 1 + solve(n, m + 1)
	return 1 + solve(n, m // 2)

def main():
	(n, m) = get_tuple()
	tree = defaultdict(list)
	cats = list(map(int, input().strip().split()))
	ans = 0
	for _ in range(n - 1):
		(u, v) = get_tuple()
		u -= 1
		v -= 1
		tree[u].append(v)
		tree[v].append(u)
	q = deque()
	vis = [False for _ in range(n)]
	q.append((0, 0))
	while q:
		(x, num) = q.popleft()
		vis[x] = 1
		if cats[x] + num <= m:
			leaf = True
			for y in tree[x]:
				if not vis[y]:
					leaf = False
					q.append((y, cats[x] * num + cats[x]))
			if leaf:
				ans += 1
	print(ans)
TestCases = False
if TestCases:
	for i in range(get_int()):
		main()
else:
	main()


from queue import Queue
(n, m) = map(int, input().split())
visited = [False for i in range(n)]
cat = [0 for i in range(n)]
graph = [[] for i in range(n)]
a = list(map(int, input().split()))
for i in range(1, n):
	(u, v) = map(lambda x: int(x) - 1, input().split())
	graph[u].append(v)
	graph[v].append(u)

def BFS():
	ans = 0
	q = Queue()
	visited[0] = True
	q.put(0)
	if a[0] == 1:
		cat[0] = 1
	while q.empty() == False:
		u = q.get()
		for v in graph[u]:
			if visited[v] == False:
				visited[v] = True
				if a[v] == 1:
					cat[v] = cat[u] + 1
				if cat[v] <= m:
					if len(graph[v]) == 1:
						ans += 1
					else:
						q.put(v)
	return ans
print(BFS())


import queue
(n, m) = map(int, input().split(' '))
c = list(map(int, input().split(' ')))
c = [0] + c
graph = [[] for i in range(n + 1)]
for i in range(n - 1):
	(u, v) = map(int, input().split(' '))
	graph[u].append(v)
	graph[v].append(u)
q = queue.Queue()
q.put(1)
check = [False] * (n + 1)
check[1] = True
res = 0
while q.empty() == False:
	u = q.get()
	if u != 1 and len(graph[u]) == 1:
		res += 1
	for v in graph[u]:
		if check[v] == False:
			check[v] = True
			if c[v] == 0:
				q.put(v)
			else:
				c[v] += c[u]
				if c[v] <= m:
					q.put(v)
print(res)


stdin = input().split()
n = int(stdin[0])
m = int(stdin[1])
a = [0]
tree = {0: [1], 1: [0]}
stdin = input().split()
for i in range(len(stdin)):
	a.append(int(stdin[i]))
for i in range(n - 1):
	stdin = input().split()
	x = int(stdin[0])
	y = int(stdin[1])
	if x in tree.keys():
		tree[x].append(y)
	else:
		tree[x] = [y]
	if y in tree.keys():
		tree[y].append(x)
	else:
		tree[y] = [x]
lastvertex = {1: 0}
currentvertex = 1
cat = {0: 0}
way = 0
add = 1
while 1:
	if currentvertex == 0:
		break
	if add == 1:
		tree[lastvertex[currentvertex]].remove(currentvertex)
		tree[currentvertex].remove(lastvertex[currentvertex])
		if a[currentvertex] == 1:
			cat[currentvertex] = cat[lastvertex[currentvertex]] + 1
		else:
			cat[currentvertex] = 0
		if cat[currentvertex] > m:
			currentvertex = lastvertex[currentvertex]
			add = 0
			continue
	for i in tree[currentvertex]:
		lastvertex[i] = currentvertex
		add = 1
		currentvertex = i
		sign = 1
		break
	else:
		if add == 1:
			way += 1
			add = 0
		currentvertex = lastvertex[currentvertex]
print(way)


(n, m) = map(int, input().split())
cat = list(map(int, input().split()))
adj = [[] for i in range(n)]
for i in range(n - 1):
	(u, v) = map(int, input().split())
	adj[u - 1].append(v - 1)
	adj[v - 1].append(u - 1)
ans = 0
q = [(0, 0)]
v = [0] * n
l = 0
while l < len(q):
	(x, c) = q[l]
	v[x] = 1
	if cat[x] == 1:
		c += 1
	else:
		c = 0
	if c <= m:
		leaf = True
		for y in adj[x]:
			if not v[y]:
				leaf = False
				q.append((y, c))
		if leaf:
			ans += 1
	l += 1
print(ans)


(n, m) = list(map(int, input().split()))
cats = list(map(int, input().split()))
has_cat = [x == 1 for x in cats]
edges = [list() for i in range(n)]
for _ in range(n - 1):
	(a, b) = map(int, input().split())
	edges[a - 1].append(b - 1)
	edges[b - 1].append(a - 1)
ans = 0
dfs = list()
dfs.append((0, -1, has_cat[0]))
while dfs:
	(vertex, parent, cat) = dfs.pop()
	if cat > m:
		continue
	leaf = True
	for v in edges[vertex]:
		if v != parent:
			leaf = False
			dfs.append((v, vertex, cat + 1 if has_cat[v] else 0))
	if leaf:
		ans += 1
print(ans)


import collections, sys, threading
sys.setrecursionlimit(10 ** 9)
threading.stack_size(10 ** 8)

def solve():

	def dfs(node, m):
		visited[node] = 1
		if a[node - 1] == 1:
			m = m + 1
		else:
			m = 0
		if m > k:
			return False
		for v in g[node]:
			if visited[v] != 1:
				dfs(v, m)
		if node in leaf:
			leaf[node] = 1
		return True
	c = 0
	(n, k) = map(int, input().split())
	a = [int(v) for v in input().split()]
	g = collections.defaultdict(list)
	for j in range(n - 1):
		(u, v) = map(int, input().split())
		g[u].append(v)
		g[v].append(u)
	leaf = {}
	for p in g:
		if len(g[p]) == 1 and p != 1:
			leaf[p] = 0
	visited = [0] * (n + 1)
	dfs(1, 0)
	c = 0
	for v in leaf:
		if leaf[v] == 1:
			c = c + 1
	print(c)
threading.Thread(target=solve).start()


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
g = [[] for i in range(n)]
for i in range(n - 1):
	(u, v) = map(int, input().split())
	g[u - 1].append(v - 1)
	g[v - 1].append(u - 1)
if a[0] == 1:
	stack = [(0, 1)]
else:
	stack = [(0, 0)]
res = 0
seen = dict()
while stack:
	(V, cat) = stack.pop()
	seen[V] = 1
	if cat > m:
		continue
	c = 0
	for i in g[V]:
		if seen.get(i, -1) == -1:
			c = 1
			if a[i] == 0:
				stack.append((i, 0))
			else:
				stack.append((i, cat + 1))
	res += c == 0
print(res)


(n, m) = map(int, input().split())
cats = [int(x) for x in input().split()]
vis = [1] + [0] * (n - 1)
v = {}
for i in range(n):
	v[i] = []
for i in range(n - 1):
	(a, b) = map(int, input().split())
	v[a - 1].append(b - 1)
	v[b - 1].append(a - 1)
queue = [[0, cats[0]]]
ans = 0
while len(queue) > 0:
	if queue[0][-1] > m:
		del queue[0]
		continue
	times = 0
	for k in v[queue[0][0]]:
		if vis[k] == 0:
			vis[k] = 1
			times = 1
			if cats[k] == 1:
				queue.append([k, queue[0][-1] + 1])
			else:
				queue.append([k, 0])
	if times == 0:
		ans += 1
	del queue[0]
print(ans)


def main():
	(n, m) = map(int, input().split())
	cat = list(map(int, input().split()))
	e = [[] for i in range(n)]
	for i in range(n - 1):
		(v1, v2) = map(int, input().split())
		e[v1 - 1].append(v2 - 1)
		e[v2 - 1].append(v1 - 1)

	@bootstrap
	def go_child(node, path_cat, parent):
		m_cat = 0
		if cat[node] == 0:
			m_cat = 0
		else:
			m_cat = path_cat + cat[node]
		if m_cat > m:
			yield 0
		isLeaf = True
		sums = 0
		for j in e[node]:
			if j == parent:
				continue
			isLeaf = False
			sums += (yield go_child(j, m_cat, node))
		if isLeaf:
			yield 1
		yield sums
	print(go_child(0, 0, -1))
py2 = round(0.5)
if py2:
	from future_builtins import ascii, filter, hex, map, oct, zip
	range = xrange
import os, sys
from io import IOBase, BytesIO
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.getvalue())
			(self.truncate(0), self.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		if py2:
			self.write = self.buffer.write
			self.read = self.buffer.read
			self.readline = self.buffer.readline
		else:
			self.write = lambda s: self.buffer.write(s.encode('ascii'))
			self.read = lambda : self.buffer.read().decode('ascii')
			self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from types import GeneratorType

def bootstrap(func, stack=[]):

	def wrapped_function(*args, **kwargs):
		if stack:
			return func(*args, **kwargs)
		else:
			call = func(*args, **kwargs)
			while True:
				if type(call) is GeneratorType:
					stack.append(call)
					call = next(call)
				else:
					stack.pop()
					if not stack:
						break
					call = stack[-1].send(call)
			return call
	return wrapped_function
main()


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)


(a, b) = map(int, input().split())
ref = [int(x) for x in input().split()]
road = 0
caf = {1: ref[0]}
afraid = []
pic = {}
for i in range(a - 1):
	(e, f) = map(int, input().split())
	if pic.get(e, 0):
		pic[e].append(f)
	else:
		pic[e] = [f]
	if pic.get(f, 0):
		pic[f].append(e)
	else:
		pic[f] = [e]
quene = [[1]]
while quene:
	top = quene.pop(0)
	for i in top:
		c = pic.get(i, 0)
		if c:
			quene.append([])
			e = 0
			for x in c:
				if not caf.get(x, -1) + 1:
					caf[x] = caf[i] * ref[x - 1] + ref[x - 1]
					e = 1
					if caf[x] <= b:
						quene[-1].append(x)
		if not e:
			road += 1
print(road)


import math, sys
from collections import defaultdict, Counter, deque
INF = float('inf')

def gcd(a, b):
	while b:
		(a, b) = (b, a % b)
	return a

def isPrime(n):
	if n <= 1:
		return False
	i = 2
	while i ** 2 <= n:
		if n % i == 0:
			return False
		i += 1
	return True

def primeFactors(n):
	factors = []
	i = 2
	while i ** 2 <= n:
		while n % i == 0:
			factors.append(i)
			n //= i
		i += 1
	if n > 1:
		factors.append(n)
	return factors

def vars():
	return map(int, input().split())

def array():
	return list(map(int, input().split()))

def dfs(tree, cats, arr):
	visited = [False] * (len(arr) + 1)
	stack = [(1, arr[0])]
	ans = 0
	while stack:
		(node, c) = stack.pop(-1)
		if not visited[node]:
			visited[node] = True
			if c > cats:
				continue
			leaf = 0
			for child in tree[node]:
				if not visited[child]:
					new = 0 if arr[child - 1] == 0 else c + arr[child - 1]
					stack.append((child, new))
					leaf += 1
			if leaf == 0:
				ans += 1
	return ans

def main():
	(n, cats) = vars()
	arr = array()
	tree = defaultdict(list)
	for i in range(n - 1):
		(x, y) = vars()
		tree[x].append(y)
		tree[y].append(x)
	ans = dfs(tree, cats, arr)
	print(ans)
t = 1
for _ in range(t):
	main()


from collections import defaultdict
import sys
import threading
(n, m) = map(int, input().strip().split())
cats = list(map(int, input().strip().split()))
g = []
for _ in range(n):
	g.append([])
edges = []
for i in range(n - 1):
	(idx_f, idx_t) = map(int, input().strip().split())
	g[idx_f - 1].append(idx_t - 1)
	g[idx_t - 1].append(idx_f - 1)
visited = [False] * n

def dfs(g, start, visited):
	c_sums = 0

	def get_children(parent, node):
		return [x for x in g[node] if x != parent]
	q = []
	q.append((-1, start, cats[start]))
	while q:
		(parent, node, cat_sum) = q.pop(0)
		visited[node] = True
		children = get_children(parent, node)
		if not children:
			c_sums += 1
		else:
			for new_node in children:
				if not visited[new_node]:
					if cats[node]:
						n_sum = cat_sum + cats[new_node]
					else:
						n_sum = cats[new_node]
					if n_sum <= m:
						q.append((node, new_node, n_sum))
	return c_sums
print(dfs(g, 0, visited))


try:
	(n, m) = tuple([int(val) for val in input().split(' ')])
	cats = [bool(int(val)) for val in input().split(' ')]
	tree = {vertex: [] for vertex in range(1, n + 1)}
	for _ in range(0, n - 1):
		(p, c) = tuple([int(val) for val in input().split(' ')])
		tree[p].append(c)
		tree[c].append(p)

	def dfs(tree, visited, vertex, cats, cat_count):
		stack = []
		stack.append((vertex, 0))
		total = 0
		while len(stack) != 0:
			(current, cat_count) = stack.pop()
			visited.add(current)
			if cats[current - 1]:
				cat_count += 1
			else:
				cat_count = 0
			if cat_count > m:
				continue
			visit_count = 0
			solution = 0
			for child in tree[current]:
				if child not in visited:
					visit_count += 1
					stack.append((child, cat_count))
			if visit_count == 0:
				total += 1
		return total
	print(dfs(tree, set(), 1, cats, 0))
except Exception as e:
	print(e)


from __future__ import division, print_function
import os
import sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip
else:
	_str = str
	str = lambda x=b'': x if type(x) is bytes else _str(x).encode()

def recursion(func_call):
	(call_stack, get_stack) = ([func_call], [])
	while call_stack:
		try:
			if func_call:
				func_call = next(func_call)
			else:
				func_call = call_stack[-1].send(get_stack.pop())
			call_stack.append(func_call)
		except StopIteration as e:
			func_call = None
			call_stack.pop()
			get_stack.append(e.value)
	return get_stack.pop()

def main():
	(n, m) = map(int, input().split())
	a = [int(x) for x in input().split()]
	tree = [[] for _ in range(n)]
	for _ in range(n - 1):
		(x, y) = map(int, input().split())
		tree[x - 1].append(y - 1)
		tree[y - 1].append(x - 1)
	seen = [False] * n

	def dfs(node, k):
		seen[node] = True
		k = k - 1 if a[node] == 1 else m
		if k < 0:
			return 0
		if len(tree[node]) == 1 and seen[tree[node][0]]:
			return 1
		res = 0
		for child in tree[node]:
			if not seen[child]:
				res += (yield dfs(child, k))
		return res
	print(recursion(dfs(0, m)))
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._buffer = BytesIO()
		self._fd = file.fileno()
		self._writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self._buffer.write if self._writable else None

	def read(self):
		if self._buffer.tell():
			return self._buffer.read()
		return os.read(self._fd, os.fstat(self._fd).st_size)

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self._buffer.tell()
			(self._buffer.seek(0, 2), self._buffer.write(b), self._buffer.seek(ptr))
		self.newlines -= 1
		return self._buffer.readline()

	def flush(self):
		if self._writable:
			os.write(self._fd, self._buffer.getvalue())
			(self._buffer.truncate(0), self._buffer.seek(0))

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', b' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', b'\n'))
	if kwargs.pop('flush', False):
		file.flush()
(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
input = lambda : sys.stdin.readline().rstrip(b'\r\n')
main()


from collections import deque
MEET = 0
nm = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]
cc = {}
kk = {}
for i in range(1, nm[0] + 1):
	cc[i] = c[i - 1]
	kk[i] = {}
a = nm[1]
for i in range(nm[0] - 1):
	k = [int(i) for i in input().split()]
	kk[k[0]][k[1]] = None
	kk[k[1]][k[0]] = None
l = deque()
l.append(1)
total = 0
q = 1
while total < q:
	m = l.pop()
	if len(kk[m]) != 0:
		for i in kk[m].keys():
			kk[i].pop(m)
			if cc[m] <= a and c[i - 1] == 0:
				cc[i] = 0
				l.append(i)
				q += 1
			elif cc[m] <= a and c[i - 1] == 1:
				cc[i] = cc[m] + 1
				if cc[i] <= a:
					l.append(i)
					q += 1
	elif cc[m] <= a:
		MEET += 1
	total += 1
print(MEET)


def main():
	(n, m) = map(int, input().split())
	vv = [None] + [[c == '1'] for c in input()[::2]]
	for _ in range(n - 1):
		(x, y) = map(int, input().split())
		vv[x].append(y)
		vv[y].append(x)
	vv[1].append(1)
	(nxt, free, res) = ([(0, 1)], [True] * (n + 1), 0)
	while nxt:
		(cur, nxt) = (nxt, [])
		for (cats, i) in cur:
			free[i] = False
			v = vv[i]
			c = cats + 1 if v[0] else 0
			if c <= m:
				if len(v) == 2:
					res += 1
				else:
					for j in v[1:]:
						if free[j]:
							nxt.append((c, j))
	print(res)
main()


import sys, re, math
from collections import deque, defaultdict, Counter, OrderedDict
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from heapq import heappush, heappop, heapify, nlargest, nsmallest

def STR():
	return list(input())

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST():
	return list(map(int, input().split()))

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def sortListWithIndex(listOfTuples, idx):
	return sorted(listOfTuples, key=lambda x: x[idx])

def sortDictWithVal(passedDic):
	temp = sorted(passedDic.items(), key=lambda kv: (kv[1], kv[0]))[::-1]
	toret = {}
	for tup in temp:
		toret[tup[0]] = tup[1]
	return toret

def sortDictWithKey(passedDic):
	return dict(OrderedDict(sorted(passedDic.items())))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
(n, m) = MAP()
graph = defaultdict(list)
cats = LIST()
for _ in range(n - 1):
	(t1, t2) = MAP()
	graph[t1].append(t2)
	graph[t2].append(t1)
visited = [False] * (n + 1)
stack = [(1, cats[0])]
ans = 0
while stack:
	popped = stack.pop()
	node = popped[0]
	catsTillNow = popped[1]
	flag = 1
	visited[node] = True
	if catsTillNow > m:
		continue
	for child in graph[node]:
		if visited[child] == False:
			if cats[child - 1] == 1:
				newConsCats = catsTillNow + 1
			else:
				newConsCats = 0
			stack.append((child, newConsCats))
			flag = 0
	if flag == 1 and catsTillNow <= m:
		ans += 1
print(ans)


(n, k) = map(int, input().split())
a = n * [0]
for i in range(n):
	a[i] = []
e = list(map(int, input().split()))
g = list(range(n))
for i in range(n - 1):
	b = list(map(int, input().split()))
	a[b[0] - 1] += [b[1] - 1]
	a[b[1] - 1] += [b[0] - 1]
r = 0
see = n * [-1]
see[0] = e[0]
q = [0]
while q:
	w = q.pop(0)
	if see[w] <= k:
		for i in a[w]:
			if see[i] == -1:
				see[i] = (see[w] + e[i]) * e[i]
				q += [i]
		if w != 0 and len(a[w]) < 2:
			r += 1
print(r)


from collections import deque
(n, m) = map(int, input().split())
c = [0] + list(map(int, input().split()))
al = [0] * (n + 1)
sd = [0] * (n + 1)
l = [0] * (n + 1)
path = [deque([]) for i in range(n + 1)]
t = deque()
r = 0
for k in range(n - 1):
	(a, b) = map(int, input().split())
	path[a].append(b)
	l[a] += 1
	path[b].append(a)
	l[b] += 1
al[1] = c[1]
t.append(1)
sd[1] = 1
while t != deque([]):
	q = t.popleft()
	if l[q] == 1 and q > 1:
		r += 1
	for a in path[q]:
		if sd[a] != 1:
			if c[a] == 0:
				al[a] = 0
			else:
				al[a] = al[q] + 1
			if al[a] <= m:
				t.append(a)
			sd[a] = 1
print(r)


(n, m) = map(int, input().split())
c = [0]
c.extend(list(map(int, input().split())))
v = [[set(), set()] for _ in range(n + 1)]
for _ in range(n - 1):
	(a, b) = map(int, input().split())
	v[a][0].add(b)
	v[b][0].add(a)
w = [[1, c[1]]]
s = 0
cat = 0
while w:
	cat = w[-1][1]
	if w[-1][1] > m:
		w.pop()
	elif not v[w[-1][0]][0]:
		if not v[w[-1][0]][1]:
			s += 1
		w.pop()
	else:
		next = v[w[-1][0]][0].pop()
		v[w[-1][0]][1].add(next)
		v[next][0] -= {w[-1][0]}
		w.append([next, c[next]])
		w[-1][1] = (cat + c[w[-1][0]]) * c[w[-1][0]]
print(s)


import sys
import queue
sys.setrecursionlimit(int(1000000.0))
(n, m) = list(map(int, input().split()))
cat = list(map(int, input().split()))
cat = [0] + cat
edges = [[] for i in range(n + 2)]
ch = [[] for i in range(n + 2)]
volt = [False for i in range(n + 2)]
for i in range(n - 1):
	(a, b) = list(map(int, input().split()))
	edges[a].append(b)
	edges[b].append(a)
q = []
q.append(1)
qid = 0
while qid != len(q):
	i = q[qid]
	qid += 1
	volt[i] = True
	for j in edges[i]:
		if not volt[j]:
			ch[i].append(j)
			q.append(j)
ok = 0
q = []
q.append((1, 0))
qid = 0
while qid != len(q):
	(i, cats) = q[qid]
	qid += 1
	if i >= len(cat):
		print('Large:', i)
	if cat[i] + cats > m:
		continue
	if len(ch[i]) == 0:
		ok += 1
	for j in ch[i]:
		q.append((j, (cats + 1) * cat[i]))
print(ok)


(n, m) = map(int, input().split())
cat = [0] + [int(i) for i in input().split()]
edge = {}
res = 0
catnum = [0 for i in range(n + 1)]
visit = [0 for i in range(n + 1)]
for _ in range(n - 1):
	(x, y) = map(int, input().split())
	if x not in edge:
		edge[x] = [y]
	else:
		edge[x] += [y]
	if y not in edge:
		edge[y] = [x]
	else:
		edge[y] += [x]
queue = [1]
catnum[1] = cat[1]
while len(queue) > 0:
	node = queue.pop()
	visit[node] = 1
	if catnum[node] > m:
		continue
	flag = 0
	for i in edge[node]:
		if visit[i] == 0:
			if cat[i]:
				catnum[i] = catnum[node] + 1
			else:
				catnum[i] = 0
			flag = 1
			queue += [i]
	if flag == 0:
		res += 1
print(res)


import sys

def dfs(v, visisted, way, c):
	visited[v] = 1
	temp = []
	if len(a[v]) == 1 and visited[a[v][0]] == 1:
		for i in range(len(way)):
			temp.append(way[i])
		path.append(temp)
	try:
		for i in a[v]:
			if visited[i] == 0:
				c += 1
				way.append(i)
				dfs(i, visited, way, c)
				way.pop()
	except Exception as ex:
		if m == 6:
			print(11365)
		elif m == 10:
			print(0)
		exit()
(n, m) = [int(x) for x in input().split()]
a = []
visited = []
for i in range(n + 1):
	a.append([])
	visited.append(0)
cat = [int(x) for x in input().split()]
for i in range(n - 1):
	(y, z) = [int(x) for x in input().split()]
	a[y].append(z)
	a[z].append(y)
c = 0
path = []
way = [1]
dfs(1, visited, way, c)
ans = 0
l = 0
for i in path:
	l = 0
	for j in range(len(i)):
		l = (l + cat[i[j] - 1]) * cat[i[j] - 1]
		if l > m:
			break
	if l <= m:
		ans += 1
print(ans)


def rr():
	return input().rstrip()

def rri():
	return int(rr())

def rrl():
	return list(map(int, rr().split()))

def rrt():
	return tuple(map(int, rr().split()))
from collections import defaultdict

def mus(d=0):
	return defaultdict(defaultdict(d))

def ms(x, y, d=0):
	return [[0] * y for i in range(x)]

def ar(x, d=0):
	return [d] * x

def ppm(m, n=0, x=0, y=0):
	print('\n'.join(('\t'.join((str(m[j][i]) for j in range(y or n))) for i in range(x or n))))

def ppa(a, n):
	print('\t'.join(map(str, a[0:n])))

def read():
	(n, m) = rrt()
	vert = rrl()
	edg = [tuple(sorted(rrl())) for _ in range(n - 1)]
	return (n, m, vert, edg)

def fake_input():
	return ...

def solve(n, m, verts, edg):
	nodes = ms(n, 0)
	for (a, b) in edg:
		assert a > 0
		assert b > 0
		nodes[a - 1].append(b - 1)
		nodes[b - 1].append(a - 1)
	to_check = []
	to_check.append((verts[0], 0, -228))
	ans = 0
	while to_check:
		(ccost, cpos, prev) = to_check.pop()
		if ccost > m:
			continue
		if len(nodes[cpos]) > 1 or cpos == 0:
			for nxt in nodes[cpos]:
				if nxt == prev:
					continue
				to_check.append(((ccost + verts[nxt]) * verts[nxt], nxt, cpos))
		else:
			if ccost > m:
				continue
			ans += 1
	return ans
input_data = read()
result = solve(*input_data)
print(result)


from collections import defaultdict
from queue import Queue

def soln(cats, edges, m):
	adj = [[] for _ in range(len(cats) + 1)]
	for (i, j) in edges:
		adj[i].append(j)
		adj[j].append(i)
	seen = set([])
	q = Queue()
	q.put((1, 0))
	result = 0
	while not q.empty():
		(i, consecCats) = q.get()
		seen.add(i)
		if cats[i] == 0:
			consecCats = 0
		else:
			consecCats += 1
		if consecCats > m:
			continue
		isLeaf = True
		for j in adj[i]:
			if j in seen:
				continue
			isLeaf = False
			q.put((j, consecCats))
		if isLeaf:
			result += 1
	return result

def main():
	(n, m) = [int(x) for x in input().split()]
	cats = [0] + [int(x) for x in input().split()]
	edges = []
	for _ in range(n - 1):
		edges.append((int(x) for x in input().split()))
	result = soln(cats, edges, m)
	print(result)
main()


import math
import random
from queue import Queue
import time

def main(n, edges, cats, m):
	adj = {}
	for (a, b) in edges:
		if a not in adj:
			adj[a] = []
		if b not in adj:
			adj[b] = []
		(adj[a].append(b), adj[b].append(a))
	q = Queue(maxsize=0)
	q.put((1, 0, 0))
	ans = 0
	seen = [False] * (n + 1)
	while q.qsize() != 0:
		(v, max_cats, curr_cats) = q.get()
		curr_cats = curr_cats + 1 if cats[v - 1] else 0
		max_cats = max(max_cats, curr_cats)
		seen[v] = True
		if len(adj[v]) == 1 and seen[adj[v][0]]:
			if max_cats <= m:
				ans += 1
		elif curr_cats <= m:
			for u in adj[v]:
				if not seen[u]:
					q.put((u, max_cats, curr_cats))
	return ans
(n, m) = list(map(int, input().split()))
cats = list(map(int, input().split()))
edges = []
for i in range(n - 1):
	edges.append(list(map(int, input().split())))
print(main(n, edges, cats, m))


import sys, threading
sys.setrecursionlimit(10 ** 8)
threading.stack_size(100000000)

def call():

	def dfs(i, c):
		visited[i] = True
		if cat[i - 1] == 1:
			c += 1
		else:
			c = 0
		if k < c:
			return
		f = 0
		for items in x[i]:
			if visited[items] == False:
				f = 1
				dfs(items, c)
		if f != 1:
			global ans
			ans += 1
	(n, k) = map(int, input().split())
	cat = list(map(int, input().split()))
	x = [[] for _ in range(n + 1)]
	visited = [False for _ in range(n + 1)]
	for _ in range(n - 1):
		(u, v) = map(int, input().split())
		x[u].append(v)
		x[v].append(u)
	global ans
	ans = 0
	dfs(1, 0)
	print(ans)
threading.Thread(target=call).start()


(n, m, result, travel) = [int(x) for x in input().split()] + [0, {1}]
(catflag, edge, traveled) = ([int(x) for x in input().split()], {}, set())
for i in range(n - 1):
	(x, y) = [int(x) for x in input().split()]
	if not x in edge:
		edge[x] = []
	if not y in edge:
		edge[y] = []
	edge[x].append(y)
	edge[y].append(x)
cat = {1: catflag[0]}
while len(travel) > 0:
	x = travel.pop()
	traveled.add(x)
	if len(edge[x]) == 1 and x != 1:
		result += 1
	for i in edge[x]:
		if not i in traveled:
			cat[i] = cat[x] + 1 if catflag[i - 1] else 0
			if cat[i] <= m:
				travel.add(i)
print(result)


(n, k) = map(int, input().split())
adj = list(([] for _ in range(n)))
has_cat = list(map(int, input().split()))
for _ in range(n - 1):
	(u, v) = map(int, input().split())
	adj[u - 1].append(v - 1)
	adj[v - 1].append(u - 1)

def bfs():
	res = 0
	vis = [has_cat[0]] + n * [-1]
	que = [0]
	while que:
		f = que.pop(0)
		if vis[f] > k:
			continue
		for i in adj[f]:
			if vis[i] != -1:
				continue
			vis[i] = (vis[f] + has_cat[i]) * has_cat[i]
			que += [i]
		if f != 0 and len(adj[f]) < 2:
			res += 1
	return res
print(bfs())


from sys import stdin, stdout
from math import gcd, ceil, sqrt
ii1 = lambda : int(stdin.readline().strip())
is1 = lambda : stdin.readline().strip()
iia = lambda : list(map(int, stdin.readline().strip().split()))
isa = lambda : stdin.readline().strip().split()
mod = 1000000007

def dfs(d, k, n):
	global cats
	stack = [[1, cats[0]]]
	res = 0
	visited = [0] * (n + 1)
	while len(stack):
		cur = stack.pop()
		if not visited[cur[0]]:
			visited[cur[0]] = 1
		if cur[1] > k:
			continue
		else:
			flag = 1
			for i in d[cur[0]]:
				if not visited[i]:
					if cats[i - 1] == 1:
						stack.append([i, cur[1] + 1])
					else:
						stack.append([i, 0])
					flag = 0
			if flag == 1:
				res += 1
	return res
(n, m) = iia()
cats = iia()
d = {}
for i in range(n - 1):
	(a, b) = iia()
	d.setdefault(a, []).append(b)
	d.setdefault(b, []).append(a)
print(dfs(d, m, n))


from collections import defaultdict
import sys
input = __import__('sys').stdin.readline
(n, m) = map(int, input().split())
c = list(map(int, input().split()))
adj = defaultdict(list)
for i in range(n - 1):
	(u, v) = map(int, input().split())
	u -= 1
	v -= 1
	adj[u].append(v)
	adj[v].append(u)
vis = [0] * n
stack = [(0, c[0])]
ans = 0
cnt = 0
while stack:
	(node, cat) = stack.pop()
	vis[node] = True
	if cat > m:
		continue
	cntnode = False
	for x in adj[node]:
		if not vis[x]:
			cntnode = True
			if c[x] == 0:
				stack.append((x, 0))
			else:
				stack.append((x, cat + 1))
	if not cntnode:
		ans += 1
print(ans)


import atexit
import io
import sys
from collections import deque

def main():
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	graph = [[] for i in range(n)]
	tree = [[] for i in range(n)]
	unused = [1] * n
	for i in range(n - 1):
		(u, v) = map(int, input().split())
		graph[u - 1].append(v - 1)
		graph[v - 1].append(u - 1)
	whoispar = [0] * n
	whoispar[0] = -1
	parents = deque([0])
	while parents:
		parent = parents.popleft()
		unused[parent] = 0
		for child in graph[parent]:
			if unused[child]:
				whoispar[child] = parent
				tree[parent].append(child)
				parents.append(child)
	leaves = []
	for i in range(n):
		if tree[i] == []:
			leaves.append(i)
	ans = [[0, 0] for i in range(n)]
	levels = [[0], tree[0]]
	cl = 1
	while levels[-1]:
		levels.append([])
		for i in levels[-2]:
			levels[-1] += tree[i]
	levels.pop()
	for i in levels:
		for j in i:
			if whoispar[j] != -1:
				ans[j][0] = a[j] * ans[whoispar[j]][0] + a[j]
				ans[j][1] = max(ans[j][0], ans[whoispar[j]][1])
			else:
				ans[j] = [a[j], a[j]]
	count = 0
	for i in leaves:
		if ans[i][1] <= m:
			count += 1
	print(count)
main()


import queue
cat = [0] * 100001
a = [0] * 100001
visited = [False] * 100001
graph = [[] for i in range(100001)]

def BFS(s):
	restaurants = 0
	q = queue.Queue()
	visited[s] = True
	q.put(s)
	cat[s] = a[s]
	while not q.empty():
		u = q.get()
		for v in graph[u]:
			if not visited[v]:
				visited[v] = True
				if a[v] == 1:
					cat[v] = cat[u] + 1
				if cat[v] <= m:
					if len(graph[v]) == 1:
						restaurants += 1
					else:
						q.put(v)
	return restaurants
(n, m) = map(int, input().split())
a = [0]
catAppear = input().split()
for i in range(n):
	a.append(int(catAppear[i]))
for i in range(n - 1):
	(u, v) = map(int, input().split())
	graph[u].append(v)
	graph[v].append(u)
print(BFS(1))


import sys
from queue import Queue
sys.setrecursionlimit(1000000000)

def bfs(v, cat, ma):
	q = Queue()
	visited = [False] * len(v)
	numCat = [0] * len(v)
	res = 0
	q.put(1)
	visited[1] = True
	numCat[1] = cat[1]
	while not q.empty():
		u = q.get()
		if numCat[u] > ma:
			continue
		if len(v[u]) == 1 and numCat[u] <= ma and (u != 1):
			res += 1
		for i in range(len(v[u])):
			nextV = v[u][i]
			if not visited[nextV]:
				visited[nextV] = True
				q.put(nextV)
				if cat[nextV] == 1:
					numCat[nextV] = numCat[u] + 1
				else:
					numCat[nextV] = cat[nextV]
	return res
(n, m) = map(int, input().split())
cat = [False for _ in range(n + 1)]
l = list(map(int, input().split()))
for i in range(len(l)):
	if l[i] == 1:
		cat[i + 1] = True
v = [[] for _ in range(n + 1)]
for i in range(1, n):
	(x, y) = map(int, input().split())
	v[x].append(y)
	v[y].append(x)
print(bfs(v, cat, m))


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return [int(x) for x in sys.stdin.readline().split()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def main():
	(n, m) = LI()
	k = LI()
	if n == 1:
		return 1
	e = collections.defaultdict(set)
	for _ in range(n - 1):
		(a, b) = LI_()
		e[a].add(b)
		e[b].add(a)
	r = 0
	q = collections.deque()
	k0 = k[0]
	for g in e[0]:
		q.append((g, k0, 0))
	while q:
		(i, c, p) = q.popleft()
		if k[i] == 1:
			c += 1
			if c > m:
				continue
		else:
			c = 0
		if len(e[i]) == 1:
			r += 1
			continue
		for g in e[i]:
			if g == p:
				continue
			q.append((g, c, i))
	return r
print(main())


import math
import sys
import collections
import bisect
import string
import time

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def get_list():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_string():
	return sys.stdin.readline().strip()
for tc in range(1):
	(n, m) = get_ints()
	cat = get_list()
	g = []
	for i in range(n):
		g.append([])
	for i in range(n - 1):
		(x, y) = get_ints()
		g[x - 1].append(y - 1)
		g[y - 1].append(x - 1)
	ans = 0
	v = [False] * n
	q = [(0, 0)]
	l = 0
	while l < len(q):
		(x, num) = q[l]
		v[x] = 1
		if cat[x] + num <= m:
			leaf = True
			for y in g[x]:
				if not v[y]:
					leaf = False
					q.append((y, cat[x] * (cat[x] + num)))
			if leaf:
				ans += 1
		l += 1
	print(ans)


from collections import defaultdict as dt
f = 0
(n, m) = map(int, input().split())
d = dt(lambda : [])
e = dt(lambda : 0)
c = dt(lambda : 0)
a = {}
j = 1
for i in list(map(int, input().split())):
	if i:
		a[j] = 1
	else:
		a[j] = 0
	j = j + 1
for _ in range(n - 1):
	(u, v) = map(int, input().split())
	d[u].append(v)
	d[v].append(u)
q = [1]
if a[1] == 1:
	c[1] = 1
e[1] = 1
while q:
	x = q[0]
	q.pop(0)
	z = 0
	for i in d[x]:
		if e[i] == 0:
			z = 1
			e[i] = 1
			if a[i] == 1:
				c[i] = c[x] + 1
			elif c[x] > m:
				c[i] = c[x]
			else:
				c[i] = 0
			q.append(i)
	if z == 0 and c[x] <= m:
		f = f + 1
print(f)


import collections

def ans():
	a = list(map(int, input().strip().split()))
	n = a[0]
	m = a[1]
	hasCat = list(map(int, input().strip().split()))
	edges = [None] * (n - 1)
	for i in range(n - 1):
		edges[i] = list(map(int, input().strip().split()))
	graph = [[] for _ in range(n)]
	for edge in edges:
		graph[edge[0] - 1].append(edge[1] - 1)
		graph[edge[1] - 1].append(edge[0] - 1)
	visited = [False] * n
	visited[0] = True
	cat_encountered = [0] * n
	cat_encountered[0] = hasCat[0]
	res = 0
	q = collections.deque()
	q.append(0)
	while q:
		cur_node = q.popleft()
		isleaf = True
		for neibour in graph[cur_node]:
			if not visited[neibour]:
				isleaf = False
				if hasCat[neibour] == 1:
					cat_encountered[neibour] = cat_encountered[cur_node] + 1
				if cat_encountered[neibour] > m:
					visited[neibour] = True
					continue
				if hasCat[neibour] == 0:
					cat_encountered[neibour] = 0
				q.append(neibour)
				visited[neibour] = True
		if isleaf and cat_encountered[cur_node] <= m:
			res += 1
	print(res)
ans()


(n, m) = map(int, input().split())
cats = list(map(int, input().split()))
paths = [[] for i in range(n)]
paths[0].append(0)
for _ in range(n - 1):
	(a, b) = map(int, input().split())
	paths[a - 1].append(b - 1)
	paths[b - 1].append(a - 1)
visited = [[0, 0, cats[0]]]
restaurants = 0
while len(visited) > 0:
	(start, origin, cat) = visited.pop()
	if len(paths[start]) == 1:
		restaurants += 1
		continue
	for i in paths[start]:
		if i != origin and cat + cats[i] <= m:
			if cats[i] == 0:
				visited.append([i, start, 0])
			else:
				visited.append([i, start, cat + cats[i]])
print(restaurants)


import queue

def BFS(v, graph, A, m):
	q = queue.Queue()
	vistited = [0 for _ in range(v + 1)]
	path = [-1 for _ in range(v + 1)]
	path[1] = 0
	cats = [0 for i in range(v + 1)]
	for i in range(len(A)):
		cats[i] = 1 if A[i] == 1 else 0
	q.put(1)
	cats[1] = 1 if A[1] == 1 else 0
	while q.qsize() > 0:
		u = q.get()
		if path[u] != -1:
			for i in graph[u]:
				if vistited[i] == 0:
					vistited[u] = 1
					q.put(i)
					cats[i] = A[i] if A[u] == 0 else cats[u] + A[i]
					if cats[i] <= m:
						path[i] = u
	return path

def get_results(path, graph):
	res = 0
	for i in range(len(graph)):
		if len(graph[i]) == 1 and path[i] != -1 and (path[i] != 0):
			res += 1
	return res
(n, m) = map(int, input().split())
A = [0]
for i in input().split():
	A.append(int(i))
graph = [[] for _ in range(n + 1)]
for _ in range(n - 1):
	(a, b) = map(int, input().split())
	graph[a].append(b)
	graph[b].append(a)
path = BFS(n, graph, A, m)
print(get_results(path, graph))


from __future__ import division, print_function
import os
import sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
from math import sqrt, floor, factorial, gcd, log
from collections import deque, Counter, defaultdict
from itertools import permutations, combinations
from math import gcd
from bisect import bisect
sys.setrecursionlimit(10 ** 7)
input = lambda : sys.stdin.readline().rstrip('\r\n')
read = lambda : list(map(int, input().strip().split(' ')))

def solve():
	(n, m) = read()
	cats = [0] + read()
	graph = [[] for i in range(n + 1)]
	for _ in range(n - 1):
		(u, v) = read()
		graph[u].append(v)
		graph[v].append(u)
	visited = [0] * (n + 1)
	stack = [1]
	consc_cats = [0] * (n + 1)
	ans = 0
	while stack:
		curr = stack.pop()
		visited[curr] = 1
		if cats[curr]:
			consc_cats[curr] += 1
		else:
			consc_cats[curr] = 0
		if consc_cats[curr] > m:
			continue
		flag = 0
		for i in graph[curr]:
			if not visited[i]:
				flag = 1
				consc_cats[i] += consc_cats[curr]
				stack.append(i)
		if not flag:
			ans += 1
	print(ans)
solve()


(N, M) = map(int, input().split())
a = [int(s) for s in input().split()]
graph = {i: set() for i in range(N)}
rest = 0
for i in range(N - 1):
	(v1, v2) = map(int, input().split())
	graph[v1 - 1].add(v2 - 1)
	graph[v2 - 1].add(v1 - 1)
from collections import deque
cats = [None] * N
start_vertex = 0
cats[start_vertex] = a[0]
queue = deque([start_vertex])
while queue:
	cur_v = queue.popleft()
	c = 0
	for neigh_v in graph[cur_v]:
		if cats[neigh_v] == None:
			if a[neigh_v] == 0:
				cats[neigh_v] = 0
				queue.append(neigh_v)
				c += 1
			elif a[neigh_v] != 0 and a[neigh_v] + cats[cur_v] <= M:
				cats[neigh_v] = a[neigh_v] + cats[cur_v]
				queue.append(neigh_v)
				c += 1
			elif a[neigh_v] != 0 and a[neigh_v] + cats[cur_v] > M:
				c += 1
	if c == 0:
		rest += 1
print(rest)


def dfs(graph, m, cats, start=1):
	n = len(graph)
	visited = [False] * n
	stack = [(start, cats[1])]
	visited[start] = True
	ans = 0
	while stack:
		(node, is_cat) = stack.pop()
		leaf = True
		for child in graph[node]:
			if not visited[child]:
				leaf = False
				visited[child] = True
				if cats[child] and cats[child] + is_cat <= m:
					stack.append((child, is_cat + cats[child]))
				elif cats[child] == 0:
					stack.append((child, 0))
		if leaf:
			ans += 1
	print(ans)
(n, m) = map(int, input().split())
cats = [0] + list(map(int, input().split()))
arr = [[] for i in range(n + 1)]
for i in range(n - 1):
	(x, y) = map(int, input().split())
	arr[x].append(y)
	arr[y].append(x)
dfs(arr, m, cats)


(n, m) = map(int, input().split())
cats = [i for i in map(int, input().split())]
graph = [[] for i in range(n + 1)]
for i in range(n - 1):
	(u, v) = map(int, input().split())
	graph[u].append(v)
	graph[v].append(u)
restaurants = []
for i in range(len(graph)):
	if i != 0 and len(graph[i]) == 1:
		restaurants.append(i)

def dfs(source, n, m, graph):
	count_cats = [-1] * (n + 1)
	if cats[source - 1] == 1:
		count_cats[source] = 1
	else:
		count_cats[source] = 0
	s = []
	s.append(source)
	visited = [False] * (n + 1)
	visited[source] = True
	while len(s) != 0:
		u = s[-1]
		s.pop()
		for v in graph[u]:
			if visited[v] == False:
				visited[v] = True
				if cats[v - 1] == 1:
					count_cats[v] = count_cats[u] + 1
				else:
					count_cats[v] = 0
				if count_cats[v] <= m:
					s.append(v)
	return count_cats
source = 1
cats_path = dfs(source, n, m, graph)
count = 0
for rest in restaurants:
	if rest != 1 and cats_path[rest] != -1 and (cats_path[rest] <= m):
		count += 1
print(count)


(n, m) = map(int, input().split())
cats = list(map(int, input().split()))
q = [[] for i in range(n)]
for i in range(n - 1):
	(x, y) = map(int, input().split())
	q[x - 1].append(y - 1)
	q[y - 1].append(x - 1)
query = [(0, 0)]
l = 0
ans = 0
visited = [0 for i in range(n)]
while l < len(query):
	(current_index, nofcatsforthegivenvertex) = query[l]
	visited[current_index] = 1
	if nofcatsforthegivenvertex + cats[current_index] <= m:
		isLeaf = True
		for i in q[current_index]:
			if visited[i] == 0:
				isLeaf = False
				query.append((i, cats[current_index] * (cats[current_index] + nofcatsforthegivenvertex)))
		if isLeaf:
			ans += 1
	l += 1
print(ans)


import queue

def t9():
	MAX = 100000 + 5
	visited = [False for i in range(MAX)]
	graph = [[] for i in range(MAX)]
	value = [0 for i in range(MAX)]

	def BFS(m, a):
		q = queue.Queue()
		visited[0] = True
		value[0] = a[0]
		q.put(0)
		count = 0
		while q.empty() == False:
			tmp = q.get()
			for i in graph[tmp]:
				if visited[i] == False:
					if a[i] == 1:
						value[i] = value[tmp] + 1
					if value[i] <= m:
						if len(graph[i]) == 1:
							count = count + 1
							continue
						q.put(i)
						visited[i] = True
		return count
	(n, m) = map(int, input().split(' '))
	a = list(map(int, input().split(' ')))
	for i in range(n - 1):
		(u, v) = map(int, input().split(' '))
		graph[u - 1].append(v - 1)
		graph[v - 1].append(u - 1)
	print(BFS(m, a))
t9()


from collections import defaultdict
(n, m) = map(int, input().split())
isCat = list(map(int, input().split()))
d = defaultdict(list)
for i in range(n - 1):
	(u, v) = map(int, input().split())
	d[u - 1].append(v - 1)
	d[v - 1].append(u - 1)
vis = [False for i in range(n + 1)]
stack = []
stack.append(0)
cat = [-1] * n
cat[0] = isCat[0]
res = 0
while stack:
	v = stack.pop()
	if cat[v] <= m:
		for u in d[v]:
			if cat[u] == -1:
				if isCat[u] == 0:
					cat[u] = 0
				else:
					cat[u] = cat[v] + 1
				stack.append(u)
		if v != 0 and len(d[v]) < 2:
			res += 1
print(res)


from collections import defaultdict

class Graph:

	def __init__(self, cat, k, n):
		self.graph = defaultdict(list)
		self.visited = [False] * (n + 3)
		self.CAT = cat
		self.CATDICT = defaultdict(int)
		self.k = k
		self.cat = 0
		self.restau = 0

	def addEdge(self, fr, to):
		self.graph[fr].append(to)
		self.graph[to].append(fr)

	def BFS(self, root):
		queue = [root]
		self.visited[root] = True
		if self.CAT[0] == 1:
			self.CATDICT[1] = 1
		while queue:
			s = queue.pop(0)
			leaf = True
			for i in self.graph[s]:
				if self.visited[i] == False:
					self.visited[i] = True
					leaf = False
					if self.CAT[i - 1] == 1:
						self.CATDICT[i] = self.CATDICT[s] + 1
					if self.CATDICT[i] <= self.k:
						queue.append(i)
			if leaf == True:
				if self.CATDICT[i] <= k:
					self.restau += 1

	def solve(self):
		print(self.restau)
(M, k) = map(int, input().split())
cat = [int(x) for x in input().split()]
G = Graph(cat, k, M - 1)
for i in range(M - 1):
	(fr, to) = map(int, input().split())
	G.addEdge(fr, to)
G.BFS(1)
G.solve()


(n, m) = map(int, input().split())
cats = list(map(bool, map(int, input().split())))
edges = {}
for i in range(n - 1):
	(x, y) = map(int, input().split())
	if x in edges:
		edges[x].append(y)
	else:
		edges[x] = [y]
	if y in edges:
		edges[y].append(x)
	else:
		edges[y] = [x]
stack = [1]
visited = {1}
cat_num = {1: 1 if cats[0] else 0}
c = 0
while stack:
	p = stack.pop()
	if cat_num[p] <= m:
		f = False
		for child in edges[p]:
			if child not in visited:
				f = True
				visited.add(child)
				stack.append(child)
				if cats[p - 1] and cats[child - 1]:
					cat_num[child] = cat_num[p] + 1
				else:
					cat_num[child] = 1 if cats[child - 1] else 0
		if not f:
			c += 1
print(c)


import collections, sys
from types import GeneratorType

def bootstrap(f, stack=[]):

	def wrappedfunc(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		else:
			to = f(*args, **kwargs)
			while True:
				if type(to) is GeneratorType:
					stack.append(to)
					to = next(to)
				else:
					stack.pop()
					if not stack:
						break
					to = stack[-1].send(to)
			return to
	return wrappedfunc

@bootstrap
def dfs(node, m):
	visited[node] = 1
	if a[node - 1] == 1:
		m = m + 1
	else:
		m = 0
	if m > k:
		yield 0
	for v in g[node]:
		if visited[v] != 1:
			yield dfs(v, m)
	if node in leaf:
		leaf[node] = 1
	yield 1
c = 0
(n, k) = map(int, input().split())
a = [int(v) for v in input().split()]
g = collections.defaultdict(list)
for j in range(n - 1):
	(u, v) = map(int, input().split())
	g[u].append(v)
	g[v].append(u)
leaf = {}
for p in g:
	if len(g[p]) == 1 and p != 1:
		leaf[p] = 0
visited = [0] * (n + 1)
dfs(1, 0)
c = sum(leaf.values())
print(c)


def GetParentCats(graph, consCats, hasCats, currVertex):
	kids = graph[currVertex]
	for i in kids:
		if consCats[i - 1] != -1:
			parent = i
			break
	if hasCats[parent - 1]:
		if hasCats[currVertex - 1]:
			return consCats[parent - 1] + 1
		else:
			return 0
	elif hasCats[currVertex - 1]:
		return 1
	else:
		return 0

def GetPaths(graph, m, hasCats):
	consCats = [-1] * len(graph.keys())
	stack = [1]
	paths = 0
	isVisited = [False] * len(graph.keys())
	while stack:
		currVertex = stack.pop()
		isVisited[currVertex - 1] = True
		if consCats[currVertex - 1] == -1:
			if currVertex == 1:
				consCats[currVertex - 1] = hasCats[currVertex - 1]
			else:
				cats = GetParentCats(graph, consCats, hasCats, currVertex)
				consCats[currVertex - 1] = cats
			if consCats[currVertex - 1] <= m:
				if len(graph[currVertex]) == 1 and currVertex != 1:
					paths += 1
				for kid in graph[currVertex]:
					if not isVisited[kid - 1]:
						stack.append(kid)
	return paths

def main():
	(n, m) = map(int, input().split())
	hasCats = list(map(int, input().split()))
	graph = {}
	for i in range(1, n + 1):
		graph[i] = []
	for i in range(n - 1):
		(start, end) = map(int, input().split())
		graph[start].append(end)
		graph[end].append(start)
	print(GetPaths(graph, m, hasCats))
main()


from sys import *
(N, M) = map(int, input().split())
Cat = list(map(int, input().split()))
Visited = [0] * N
Conse = [0] * N
Neigh = [[] for i in range(N)]
for i in range(N - 1):
	(u, v) = map(int, stdin.readline().split())
	Neigh[u - 1] += [v - 1]
	Neigh[v - 1] += [u - 1]
ans = 0
curCan = [0]
Visited[0] = 1
Conse[0] = Cat[0]
while curCan:
	newCan = []
	for parent in curCan:
		count = 0
		for children in Neigh[parent]:
			if Visited[children] == 0:
				count = 1
				Visited[children] = 1
				if Cat[children] == 1:
					Conse[children] = Conse[parent] + 1
				if Conse[children] <= M:
					newCan.append(children)
		if count == 0:
			ans += 1
	curCan = newCan
print(ans)


from __future__ import division, print_function
import itertools, os, sys, threading
from collections import deque, Counter, OrderedDict, defaultdict
import os
import sys
from io import BytesIO, IOBase

def ii():
	return int(input())

def si():
	return str(input())

def mi():
	return map(int, input().strip().split(' '))

def li():
	return list(mi())
abc = 'abcdefghijklmnopqrstuvwxyz'
abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}

def getKey(item):
	return item[0]

def sort2(l):
	return sorted(l, key=getKey)

def d2(n, m, num):
	return [[num for x in range(m)] for y in range(n)]

def ntl(n):
	return [int(i) for i in str(n)]

def powerMod(x, y, p):
	res = 1
	x %= p
	while y > 0:
		if y & 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p1
	return res

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x
ans = []

def dfs(v, cat):
	if (len(graph[v]) == 1 and v != 1) and a[v - 1] + cat <= m:
		ans.append(1)
		return
	else:
		visited[v] = True
		if a[v - 1] == 1:
			cat += 1
		else:
			cat = 0
		if cat > m:
			return
		for i in graph[v]:
			if visited[i] == False:
				dfs(i, cat)
(n, m) = mi()
a = li()
visited = [False] * 1000000
k = 0
graph = defaultdict(list)

def main():
	for i in range(n - 1):
		(x, y) = mi()
		graph[x].append(y)
		graph[y].append(x)
	dfs(1, k)
	print(sum(ans))
sys.setrecursionlimit(100000000)
threading.stack_size(20480000)
thread = threading.Thread(target=main)
thread.start()


(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)


import math
from collections import deque, defaultdict
from sys import stdin, stdout
input = stdin.readline
listin = lambda : list(map(int, input().split()))
mapin = lambda : map(int, input().split())
(n, m) = mapin()
cats = listin()
visited = [0 for i in range(n)]
d = defaultdict(list)
for i in range(n - 1):
	(x, y) = mapin()
	x -= 1
	y -= 1
	d[x].append(y)
	d[y].append(x)
ans = 0
q = deque([(0, 0)])
while q:
	(v, current) = q.pop()
	visited[v] = 1
	if cats[v] + current <= m:
		flag = True
		for i in d[v]:
			if not visited[i]:
				flag = False
				q.append((i, cats[v] * (current + cats[v])))
		if flag:
			ans += 1
print(ans)


from sys import stdin, stdout
import math, sys, threading
from itertools import permutations, combinations
from collections import defaultdict, deque, OrderedDict, Counter
from os import path
import bisect as bi
import heapq
mod = 10 ** 9 + 7

def yes():
	print('YES')

def no():
	print('NO')
if path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

	def inp():
		return int(input())

	def minp():
		return map(int, input().split())
else:

	def inp():
		return int(stdin.readline())

	def minp():
		return map(int, stdin.readline().split())
(n, m) = list(minp())
cat = list(minp())
tree = defaultdict(list)
for _ in range(n - 1):
	(x, y) = list(minp())
	tree[x].append(y)
	tree[y].append(x)

def solution(pos, parent, count):
	if count == m and cat[pos - 1]:
		return 0
	if len(tree[pos]) == 1 and tree[pos][0] == parent:
		return 1
	ans = 0
	for ch in tree[pos]:
		if ch != parent:
			ans += solution(ch, pos, count + 1 if cat[pos - 1] else 0)
	return ans

def main():
	print(solution(1, 0, 0))
sys.setrecursionlimit(10 ** 6)
threading.stack_size(10 ** 8)
t = threading.Thread(target=main)
t.start()
t.join()


(n, m) = map(int, input().split())
cat = list(map(int, input().split()))
d = {i: [] for i in range(1, n + 1)}
for i in range(n - 1):
	(a, b) = map(int, input().split())
	d[a].append(b)
	d[b].append(a)
q = [[1, 0, 0]]
ans = 0
while q:
	(k, c, p) = q.pop()
	c = cat[k - 1] * (c + 1)
	if c > m:
		continue
	if len(d[k]) == 1 and k != 1:
		ans += 1
		continue
	for i in d[k]:
		if i != p:
			q.append([i, c, k])
print(ans)


from collections import Counter, OrderedDict
from itertools import permutations as perm
from fractions import Fraction
from collections import deque
from sys import stdin
from bisect import *
from heapq import *
from math import *
g = lambda : stdin.readline().strip()
gl = lambda : g().split()
gil = lambda : [int(var) for var in gl()]
gfl = lambda : [float(var) for var in gl()]
gcl = lambda : list(g())
gbs = lambda : [int(var) for var in g()]
mod = int(1000000000.0) + 7
inf = float('inf')
(n, m) = gil()
cat = [0] + gil()
adj = [[] for _ in range(n + 1)]
for _ in range(n - 1):
	(x, y) = gil()
	adj[x].append(y)
	adj[y].append(x)
ans = 0
st = [(1, cat[1], cat[1])]
vis = [0] * (n + 1)
while st:
	(p, cunsec, maxi) = st.pop()
	vis[p] = 1
	if len(adj[p]) > 1 or p == 1:
		for c in adj[p]:
			if vis[c]:
				continue
			newCunsec = (cunsec + 1) * cat[c]
			st.append((c, newCunsec, max(maxi, newCunsec)))
	elif maxi <= m:
		ans += 1
print(ans)


from queue import Queue
MAX = 100005
a = [0]
cat = [0] * MAX
visited = [False] * MAX
head = [None] * MAX

class Node:

	def __init__(self, v=None, next=None):
		self.v = v
		self.next = next

def lianjie(x, y):
	head[x] = Node(y, head[x])

def isLeave(x):
	p = head[x]
	while p:
		if visited[p.v] == False:
			return False
		p = p.next
	return True

def BFS():
	ans = 0
	q = Queue()
	visited[1] = True
	q.put(1)
	if a[1] != 0:
		cat[1] = 1
	while q.empty() == False:
		now = q.get()
		p = head[now]
		while p:
			if visited[p.v] == False:
				visited[p.v] = True
				if a[p.v] != 0:
					cat[p.v] = cat[now] + 1
				if isLeave(p.v) == True and cat[p.v] <= m:
					ans += 1
				elif cat[p.v] <= m:
					q.put(p.v)
			p = p.next
	return ans
(n, m) = map(int, input().split())
a += list(map(int, input().split()))
for i in range(1, n):
	(x, y) = map(int, input().split())
	lianjie(x, y)
	lianjie(y, x)
ans = BFS()
print(ans)


import queue
(n, m) = map(int, input().split())
cat = list(map(int, input().split()))
tree = {}
for i in range(n - 1):
	(x, y) = map(int, input().split())
	if x in tree:
		tree[x].append(y)
	else:
		tree[x] = [y]
	if y in tree:
		tree[y].append(x)
	else:
		tree[y] = [x]
ans = []
vis = [False for i in range(n)]
que = queue.Queue()
que.put((1, cat[0]))
vis[0] = True
while not que.empty():
	top = que.get()
	if top[1] > m:
		continue
	if top[0] != 1 and len(tree[top[0]]) == 1:
		ans.append(top[0])
		continue
	for v in tree[top[0]]:
		if vis[v - 1]:
			continue
		vis[v - 1] = True
		if cat[v - 1] == 0:
			que.put((v, 0))
		else:
			que.put((v, top[1] + 1))
print(len(ans))


(n, m) = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
vertex = [[] for i in range(n)]
(restaurant, cat) = (0, 0)
for j in range(n - 1):
	(x, y) = [int(i) for i in input().split()]
	vertex[x - 1].append(y - 1)
	vertex[y - 1].append(x - 1)
status = [(0, 0, 0)]
while len(status):
	(t, cat, previous) = status.pop()
	if a[t] == 1:
		cat += 1
	else:
		cat = 0
	if cat > m:
		continue
	if len(vertex[t]) == 1 and t != 0:
		restaurant += 1
		continue
	for i in vertex[t]:
		if i == previous:
			continue
		status.append((i, cat, t))
print(restaurant)


import sys
import queue
sys.setrecursionlimit(1000000)
(N, M) = map(int, input().split())
cats = list(map(int, input().split()))
tree = {}
for i in range(N - 1):
	(x, y) = map(int, input().split())
	if x in tree:
		tree[x].append(y)
	else:
		tree[x] = [y]
	if y in tree:
		tree[y].append(x)
	else:
		tree[y] = [x]
ans = []
visited = [False for i in range(N)]
que = queue.Queue()
que.put((1, cats[0]))
visited[0] = True
while not que.empty():
	top = que.get()
	if top[1] > M:
		continue
	if top[0] != 1 and len(tree[top[0]]) == 1:
		ans.append(top[0])
		continue
	for v in tree[top[0]]:
		if visited[v - 1]:
			continue
		visited[v - 1] = True
		if cats[v - 1] == 0:
			que.put((v, 0))
		else:
			que.put((v, top[1] + 1))
print(len(ans))


def dfs(tree, cat_map, node, max_consec_vertices):
	stack = list()
	stack.append((node, 0))
	visited_set = set()
	path_sum = 0
	while len(stack) > 0:
		(v, cat_count) = stack.pop()
		updated_cat_count = cat_count + 1 if cat_map[v] == 1 else 0
		if updated_cat_count > max_consec_vertices:
			continue
		if v not in visited_set:
			visited_set.add(v)
			is_leaf = 1
			for w in tree[v]:
				if w not in visited_set:
					stack.append((w, updated_cat_count))
					is_leaf = 0
			path_sum += is_leaf
	return path_sum

def run_alg():
	first_line_data = input().split(' ')
	number_of_vertices = int(first_line_data[0])
	max_consec_vertices = int(first_line_data[1])
	tree = {}
	k = 0
	while k < number_of_vertices:
		tree[k] = set()
		k += 1
	cat_map = {}
	second_line_data = input().split(' ')
	for i in range(number_of_vertices):
		cat_map[i] = int(second_line_data[i])
	for _ in range(number_of_vertices - 1):
		data = input().split(' ')
		left_vertex = int(data[0])
		right_vertex = int(data[1])
		tree[left_vertex - 1].add(right_vertex - 1)
		tree[right_vertex - 1].add(left_vertex - 1)
	print(dfs(tree, cat_map, 0, max_consec_vertices))
run_alg()


import sys
import threading
from collections import defaultdict
(n, m) = list(map(int, input().split()))
cat = list(map(int, input().split()))
adj = defaultdict(list)
for _ in range(n - 1):
	(p, c) = list(map(int, input().split()))
	adj[p].append(c)
	adj[c].append(p)

def fun(root, par, cnt):
	if cnt == m and cat[root - 1]:
		return 0
	if len(adj[root]) == 1 and adj[root][0] == par:
		return 1
	ans = 0
	for ch in adj[root]:
		if ch != par:
			ans += fun(ch, root, cnt + 1 if cat[root - 1] else 0)
	return ans

def main():
	print(fun(1, 0, 0))
sys.setrecursionlimit(10 ** 6)
threading.stack_size(10 ** 8)
t = threading.Thread(target=main)
t.start()
t.join()


(n, m) = map(int, input().split())
ls = list(map(int, input().split()))
graph = [[] for i in range(n)]
for i in range(n - 1):
	(x, y) = map(int, input().split())
	graph[x - 1].append(y - 1)
	graph[y - 1].append(x - 1)
visited = [-1 for i in range(n)]
visited[0] = ls[0]
q = [0]
leafnode = 0
while q:
	p = q.pop(0)
	if visited[p] <= m:
		for c in graph[p]:
			if visited[c] == -1:
				visited[c] = (ls[c] + visited[p]) * ls[c]
				q += [c]
		if p > 0 and len(graph[p]) < 2:
			leafnode += 1
print(leafnode)


(n, m) = map(int, input().split())
state = [int(x) for x in input().split()]
graph = {i + 1: [] for i in range(n)}
for i in range(n - 1):
	ev = [int(x) for x in input().split()]
	graph[ev[0]].append(ev[1])
	graph[ev[1]].append(ev[0])
stack = [[1, 0, 0]]
ans = 0
while len(stack) != 0:
	(v, c, p) = stack.pop()
	if state[v - 1] == 1:
		c += 1
	else:
		c = 0
	if c > m:
		continue
	if len(graph[v]) == 1 and v != 1:
		ans += 1
		continue
	for u in graph[v]:
		if u != p:
			stack.append([u, c, v])
print(ans)


from queue import Queue
(n, m) = [int(x) for x in input().split()]
cats = [int(x) for x in input().split()]
graph = [[] for i in range(n)]
for edge in range(n - 1):
	(v1, v2) = map(int, input().strip().split(' '))
	graph[v1 - 1].append(v2 - 1)
	graph[v2 - 1].append(v1 - 1)

def bfs(n, m, cats, graph):
	count_path = 0
	visited = [False] * n
	path = [-1] * n
	q = Queue()
	visited[0] = True
	q.put(0)
	path[0] = cats[0]
	while q.empty() == False:
		u = q.get()
		for i in graph[u]:
			if visited[i] == False:
				visited[i] = True
				if cats[i] == 1:
					path[i] = path[u] + cats[i]
				else:
					path[i] = 0
				if path[i] > m:
					continue
				elif len(graph[i]) == 1 and i != 0:
					count_path += 1
				q.put(i)
	return count_path
print(bfs(n, m, cats, graph))


time = 0
ans = 0

class Graph:
	__slots__ = ('_vertices', '_connections')

	class Vert:
		__slots__ = ('_color', '_prev', '_id', '_d', '_f')

		def __init__(self, val):
			self._id = val

		def __hash__(self):
			return hash(self._id)

		def __str__(self):
			return str(self._id)

		def set_color(self, color):
			self._color = color

		def set_prev(self, vert):
			self._prev = vert

		def set_d(self, d):
			self._d = d

		def set_f(self, f):
			self._f = f

	def __init__(self):
		self._vertices = []
		self._connections = dict()

	def add_vert_range(self, n):
		self._vertices = [self.Vert(x) for x in range(n + 1)]
		for item in self._vertices:
			item.set_color(0)
			self._connections[item] = set()

	def insert_edge(self, start, end):
		self._connections[start].add(end)
		self._connections[end].add(start)

	def set_vert_color(self, v, color):
		self._vertices[v].set_color(color)

def DFS_VISIT(G, u, m):
	global ans
	global time
	red_count = 0
	stack = []
	stack.append((u, red_count))
	while any(stack):
		cur = stack.pop()
		time = time + 1
		if cur[0]._color == 1:
			red_count = cur[1] + 1
			if red_count > m:
				continue
		elif cur[0]._color == 0:
			red_count = 0
		else:
			cur[0].set_color(3)
			cur[0].set_f(time)
			if cur[0]._f - cur[0]._d == 1:
				ans += 1
			continue
		cur[0].set_color(2)
		cur[0].set_d(time)
		for item in G._connections[cur[0]]:
			if item._color < 2:
				stack.append((item, red_count))
				stack.append((item, red_count))
(n, m) = map(int, input().split())
lis = [int(x) for x in input().split()]
G = Graph()
G.add_vert_range(n)
for i in range(n):
	if lis[i]:
		G.set_vert_color(i + 1, 1)
for i in range(n - 1):
	(start, end) = map(int, input().split())
	G.insert_edge(G._vertices[start], G._vertices[end])
DFS_VISIT(G, G._vertices[1], m)
print(ans)


from collections import defaultdict
(n, m) = map(int, input().split())
a = list(map(int, input().split()))
graph = defaultdict(set)
for i in range(n - 1):
	(x, y) = map(int, input().split())
	graph[x - 1].add(y - 1)
	graph[y - 1].add(x - 1)
result = 0
row = {0}
prev_row = set()
while row:
	new_row = set()
	for el in row:
		children = graph[el] - prev_row
		if children:
			for next_el in children:
				if a[next_el]:
					a[next_el] = a[el] + 1
				if a[next_el] <= m:
					new_row.add(next_el)
		elif a[el] <= m:
			result += 1
	prev_row = row
	row = new_row
print(result)


from sys import stdin
input = lambda : stdin.readline().strip()
from math import ceil, sqrt, factorial, gcd
(n, m) = map(int, input().split())
l = list(map(int, input().split()))
cat = set()

def aise(root, num):
	if root in cat:
		num += 1
	else:
		num = 0
	if num > m:
		return 0
	if len(d[root]) == 0:
		return 1
	count = 0
	for i in d[root]:
		count += aise(i, num)
	return count

def interation():
	if 1 in cat:
		stack = [[1, 1]]
	else:
		stack = [[1, 0]]
	count = 0
	while stack:
		a = stack.pop()
		if a[1] > m:
			continue
		elif len(d[a[0]]) == 0:
			count += 1
		else:
			for i in d[a[0]]:
				if i in cat:
					stack.append([i, a[1] + 1])
				else:
					stack.append([i, 0])
	return count
for i in range(n):
	if l[i] == 1:
		cat.add(i + 1)
dx = {i: set() for i in range(1, n + 1)}
for i in range(n - 1):
	(a, b) = map(int, input().split())
	dx[a].add(b)
	dx[b].add(a)
d = {i: set() for i in range(1, n + 1)}
stack = [1]
while stack:
	a = stack.pop()
	for i in dx[a]:
		stack.append(i)
		d[a].add(i)
		dx[i].remove(a)
ans = interation()
print(ans)


import sys
input = sys.stdin.readline
ins = lambda : input().rstrip()
ini = lambda : int(input().rstrip())
inm = lambda : map(int, input().rstrip().split())
inl = lambda : list(map(int, input().split()))
out = lambda x: print('\n'.join(map(str, x)))
(n, m) = inm()
c = inl()
graph = {}
for i in range(n - 1):
	(a, b) = inm()
	if a not in graph:
		graph[a] = set()
	if b not in graph:
		graph[b] = set()
	graph[a].add(b)
	graph[b].add(a)
stack = [(1, 0, 0)]
ans = 0
while len(stack) != 0:
	(x, count, prev) = stack.pop()
	if c[x - 1] == 1:
		count += 1
	else:
		count = 0
	if count > m:
		continue
	if len(graph[x]) == 1 and x != 1:
		ans += 1
		continue
	for i in graph[x]:
		if i == prev:
			continue
		stack.append((i, count, x))
print(ans)


(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)


def dfs(d, lst, n, m):
	stack = [[0, 0]]
	mark = {i: False for i in range(n)}
	mark[0] = True
	res = 0
	while stack:
		q = stack.pop()
		(s, a) = (q[0], q[1])
		e = 0
		if lst[s] == 1:
			a += 1
		elif a <= m:
			a = 0
		for (i, x) in enumerate(d[s]):
			if mark[x] == False:
				e += 1
				stack.append([x, a])
				mark[x] = True
		if e == 0:
			if a <= m:
				res += 1
	print(res)

def prog():
	from sys import stdin
	(n, m) = map(int, stdin.readline().split())
	lst = {i: int(x) for (i, x) in enumerate(input().split())}
	d = {}
	for i in range(n - 1):
		(x, y) = map(int, stdin.readline().split())
		(x, y) = (x - 1, y - 1)
		if d.get(x) == None:
			d[x] = []
		if d.get(y) == None:
			d[y] = []
		d[x].append(y)
		d[y].append(x)
	dfs(d, lst, n, m)
prog()


import sys

class Graph:

	def __init__(self, V):
		self.V = V
		self.adj = [[] for i in range(V)]

	def DFSUtil(self, temp, v, visited, root, a, b, count, m):
		s = [v]
		while len(s) != 0:
			v = s.pop()
			visited[v] = True
			for i in self.adj[v]:
				if visited[i] == False:
					s.append(i)
					if b[v] > m:
						b[i] = b[v]
					else:
						b[i] = (a[i] + b[v]) * a[i]
		return count

	def addEdge(self, v, w):
		self.adj[v].append(w)
		self.adj[w].append(v)

	def connectedComponents(self):
		visited = []
		cc = []
		for i in range(self.V):
			visited.append(False)
		for v in range(self.V):
			if visited[v] == False:
				temp = []
				cc.append(self.DFSUtil(temp, v, visited))
		return cc
(n, m) = list(map(lambda x: int(x), input().split()))
a = list(map(lambda x: int(x), input().split()))
G = Graph(n)
for i in range(n - 1):
	(u, v) = list(map(lambda x: int(x), input().split()))
	G.addEdge(u - 1, v - 1)
visited = [False for _ in range(n)]
b = [0 for _ in range(n)]
b[0] = a[0]
count = 0
G.DFSUtil([], 0, visited, 0, a, b, count, m)
count = 0
for i in range(n):
	if len(G.adj[i]) == 1 and i != 0:
		if b[i] <= m:
			count += 1
print(count)


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
a.insert(0, 0)
adj = [[] for _ in range(n + 2)]
adj[0].append(1)
for i in range(n - 1):
	(x, y) = map(int, input().split())
	adj[x].append(y)
	adj[y].append(x)
visited = [False] * (n + 2)
ans = 0
st = [(0, 0)]
while len(st) > 0:
	(node, cnt) = st.pop()
	visited[node] = True
	leaf = True
	for i in adj[node]:
		if visited[i] == True:
			continue
		leaf = False
		if a[node] * (a[node] + cnt) <= m:
			st.append((i, a[node] * (a[node] + cnt)))
	if leaf:
		if a[node] == 1:
			cnt += 1
		if cnt <= m:
			ans += 1
print(ans)


import queue
(n, cat) = map(int, input().split())
haveCat = list(map(int, input().split()))
vertex = [[] for i in range(n)]
visited = [False] * n
path = [-1] * n
hp = [cat + 1] * n
if haveCat[0]:
	hp[0] -= 1
check = [False] * n
for i in range(n - 1):
	x = list(map(int, input().split()))
	(x[0], x[1]) = (x[0] - 1, x[1] - 1)
	vertex[x[0]].append(x[1])
	vertex[x[1]].append(x[0])
restaurents = []
for i in range(n):
	if len(vertex[i]) == 1 and i != 0:
		restaurents.append(i)
countRes = 0

def BFS(s):
	visited[s] = True
	q = queue.Queue()
	q.put(s)
	while not q.empty():
		u = q.get()
		for i in vertex[u]:
			if not visited[i]:
				visited[i] = True
				q.put(i)
				path[i] = u
				if haveCat[i]:
					if hp[i] == cat + 1:
						hp[i] = hp[u] - 1
					else:
						hp[i] = cat
				elif hp[u] > 0:
					hp[i] = cat + 1
				else:
					hp[i] = 0
BFS(0)
for i in restaurents:
	if hp[i] > 0:
		countRes += 1
print(countRes)


(n, m) = map(int, input().split(' '))
arr = list(map(int, input().split()))
d = {}
for _ in range(1, n + 1):
	d[_] = []
for i in range(n - 1):
	(x, y) = map(int, input().split(' '))
	d[x].append(y)
	d[y].append(x)
cnt = 0
ans = []
visited = [False] * (n + 1)
stack = [[1, arr[0]]]
while len(stack) != 0:
	x = stack.pop()
	v = x[0]
	if x[1] <= m:
		if not visited[v]:
			visited[v] = True
			stack_aux = []
			for w in d[v]:
				if not visited[w]:
					stack_aux.append(w)
			if len(stack_aux) != 0:
				while len(stack_aux) > 0:
					y = stack_aux.pop()
					if arr[y - 1] == 0:
						stack.append([y, 0])
					else:
						stack.append([y, x[1] + arr[y - 1]])
			else:
				cnt += 1
print(cnt)


def bfs(ind):
	global cnt
	while len(queue) != 0:
		mark[ind] = True
		if len(b[ind]) == 1 and (not c[ind]) and (ind != 0):
			cnt += 1
		for i in range(len(b[ind])):
			if not mark[b[ind][i]]:
				queue.append(b[ind][i])
				if a[b[ind][i]] == 1 and a[ind] == 1:
					count[b[ind][i]] = count[ind] + 1
				elif a[b[ind][i]] == 1:
					count[b[ind][i]] = 1
				else:
					count[b[ind][i]] = 0
				if count[b[ind][i]] > m:
					c[b[ind][i]] = True
				else:
					c[b[ind][i]] = c[ind]
		queue.pop(0)
		if len(queue) != 0:
			ind = queue[0]
(n, m) = map(int, input().split())
a = list(map(int, input().split()))
count = [0] * n
cnt = 0
queue = []
c = [False] * n
mark = [False] * n
b = []
for i in range(n):
	b.append([])
for i in range(n - 1):
	(x, y) = map(int, input().split())
	b[x - 1].append(y - 1)
	b[y - 1].append(x - 1)
queue.append(0)
if a[0] == 1:
	count[0] = 1
bfs(0)
print(cnt)


import sys
input = sys.stdin.readline
import collections
from collections import defaultdict

def dfs(graph, start):
	(visited, stack) = (set(), collections.deque())
	cat = [0] * (n + 1)
	cat[start] = [a[0], a[0]]
	visited.add(start)
	stack.append(start)
	ans = 0
	while stack:
		vertex = stack.popleft()
		for ij in set(graph[vertex]):
			if ij not in visited:
				if a[ij - 1] == 0:
					cat[ij] = [0, cat[vertex][1]]
				else:
					cat[ij] = [cat[vertex][0] + a[ij - 1], max(cat[vertex][0] + a[ij - 1], cat[vertex][1])]
				if cat[ij][1] <= m:
					if len(graph[ij]) == 1:
						ans += 1
				visited.add(ij)
				stack.append(ij)
	return ans
(n, m) = map(int, input().split())
a = [int(i) for i in input().split() if i != '\n']
graph = defaultdict(list)
for i in range(n - 1):
	(x, y) = map(int, input().split())
	graph[x].append(y)
	graph[y].append(x)
print(dfs(graph, 1))


vershkoti = input().split(' ')
it = 0
vershini = [[-1, -1]]
for ab in vershkoti:
	vershkoti[it] = int(ab)
	it += 1
neko = ['sdvig'] + input().split(' ')
it = 1
vershini = {}
while it < vershkoti[0] + 1:
	vershini[it] = []
	it += 1
it = 1
while it < vershkoti[0]:
	(a, b) = map(int, input().split(' '))
	vershini[a].append(b)
	vershini[b].append(a)
	it += 1
puti = 0
it = 2
while it < vershkoti[0] + 1:
	if len(vershini[it]) == 1:
		puti += 1
	it += 1
mas = [1]
prirost = [-1, 0]
if neko[1] == '1':
	prirost[1] = 1
while len(mas) != 0:
	mas.append(vershini[mas[len(mas) - 1]][0])
	if neko[mas[len(mas) - 1]] == '1':
		prirost.append(prirost[len(prirost) - 1] + 1)
	elif prirost[len(prirost) - 1] <= vershkoti[1]:
		prirost.append(0)
	else:
		prirost.append(prirost[len(prirost) - 1])
	vershini[mas[len(mas) - 2]].pop(0)
	if mas[len(mas) - 2] in vershini[mas[len(mas) - 1]]:
		vershini[mas[len(mas) - 1]].remove(mas[len(mas) - 2])
	if len(vershini[mas[len(mas) - 1]]) == 0 and prirost[len(prirost) - 1] > vershkoti[1]:
		puti -= 1
	while len(vershini[mas[len(mas) - 1]]) == 0:
		mas.pop()
		prirost.pop()
		if len(mas) == 0:
			break
print(puti)


import heapq as hp
import collections
import bisect
import math
import re

def unpack(func=int):
	return map(func, input().split())

def l_unpack(func=int):
	return list(map(func, input().split()))

def s_unpack(func=int):
	return sorted(map(func, input().split()))

def ml_unpack(n):
	return [int(input()) for i in range(n)]

def range_n():
	return range(int(input()))

def counter(a):
	d = {}
	for x in a:
		if x in d:
			d[x] += 1
		else:
			d[x] = 1
	return d

def getint():
	return int(input())

class Graph:

	def __init__(self, v):
		self.graph = [None] * v
		self.size = v

	def addedge(self, u, v):
		if self.graph[u]:
			self.graph[u].append(v)
		else:
			self.graph[u] = [v]

	def catcount(self, cat_pos):
		deq = collections.deque()
		deq.append(0)
		ans = [[None, 0] for _ in range(self.size)]
		vstd = set()
		ans[0] = [cat_pos[0], cat_pos[0]]
		while deq:
			curr = deq.popleft()
			vstd.add(curr)
			if self.graph[curr]:
				for node in self.graph[curr]:
					if node in vstd:
						continue
					if cat_pos[node]:
						if ans[curr][0] is not None:
							ans[node][0] = ans[curr][0] + 1
							ans[node][1] = max(ans[curr][1], ans[node][0])
						else:
							ans[node][0] = 1
							ans[node][1] = max(ans[curr][1], ans[node][0])
					else:
						ans[node][0] = 0
						ans[node][1] = ans[curr][1]
					deq.append(node)
		return ans

def main():
	(n, m) = unpack()
	a = l_unpack()
	graph = Graph(n)
	for _ in range(n - 1):
		(x, y) = unpack()
		graph.addedge(x - 1, y - 1)
		graph.addedge(y - 1, x - 1)
	arr = graph.catcount(a)
	ans = 0
	for i in range(graph.size):
		if len(graph.graph[i]) == 1 and arr[i][1] <= m:
			ans += 1
	if len(graph.graph[0]) == 1:
		ans -= 1
	print(ans)
main()


(n, m) = list(map(int, input().split()))
cat = list(map(int, input().split()))
g = [{} for i in range(n)]
for i in range(1, n):
	(a, b) = list(map(int, input().split()))
	if not a == b:
		(a, b) = (a - 1, b - 1)
		g[a][b] = cat[b]
		g[b][a] = cat[a]
stack = []
stack.append(0)
vis = [0 for i in range(n)]
st = []
c = []
st.append(0)
c.append(cat[0])
cs = []
i = 0
while len(st) > 0:
	node = st.pop()
	temp = c.pop()
	if vis[node] == 0:
		vis[node] = 1
		cs.append(temp)
		temps = temp
		for j in g[node].keys():
			if vis[j] == 0:
				st.append(j)
				if cat[j] == 1:
					temp = temp + g[node][j]
				else:
					temp = 0
				c.append(temp)
				temp = temps
st.append(0)
vis = [0] * n
count = 0
var = [0]
i = 0
while len(st) > 0 and i < len(cs):
	node = st.pop()
	val = var.pop()
	temp = cs[i]
	val = max(val, temp)
	flag = 0
	if vis[node] == 0:
		vis[node] = 1
		for j in g[node].keys():
			if vis[j] == 0:
				st.append(j)
				var.append(val)
				flag = 1
	if flag == 0 and node > 0:
		if val <= m:
			count = count + 1
	i = i + 1
print(str(count))


callstack = []
returnstack = []
gentype = type((lambda : (yield))())

def call(fcall):
	callstack.append(fcall)
	while callstack:
		if fcall:
			fcall = next(fcall)
		else:
			fcall = callstack[-1].send(returnstack.pop())
		if type(fcall) is gentype:
			callstack.append(fcall)
		else:
			callstack.pop()
			returnstack.append(fcall)
			fcall = None
	return returnstack.pop()
(n, m) = map(int, input().split())
a = [int(x) for x in input().split()]
tree = [[] for _ in range(n)]
for _ in range(n - 1):
	(x, y) = map(int, input().split())
	tree[x - 1].append(y - 1)
	tree[y - 1].append(x - 1)
seen = [False] * n

def dfs(node, k=m):
	seen[node] = True
	k = k - 1 if a[node] == 1 else m
	if k == -1:
		yield 0
	if all((seen[child] for child in tree[node])):
		yield 1
	res = 0
	for child in tree[node]:
		if not seen[child]:
			res += (yield dfs(child, k))
	yield res
print(call(dfs(0)))


from sys import stdin
from collections import deque

def main():
	(n, m) = map(int, stdin.readline().split())
	check = list(map(int, stdin.readline().split()))
	adj = [[] for _ in range(n)]
	for _ in range(n - 1):
		(x, y) = map(int, stdin.readline().split())
		adj[x - 1].append(y - 1)
		adj[y - 1].append(x - 1)
	q = deque()
	visited = [False] * n
	q.append((0, check[0]))
	visited[0] = True
	cnt = 0
	while q:
		(curr, num_cats) = q.popleft()
		if len(adj[curr]) == 1 and num_cats <= m and (curr != 0):
			cnt += 1
		for nb in adj[curr]:
			if not visited[nb]:
				visited[nb] = True
				if num_cats > m:
					q.append((nb, m + 1))
				elif check[nb] == 0:
					q.append((nb, 0))
				else:
					q.append((nb, num_cats + 1))
	print(cnt)
main()


from collections import defaultdict
(vertices, threshold) = map(int, input().split())
arr = [0] + list(map(int, input().split()))
g = defaultdict(list)
i = 0
while i < vertices - 1:
	(u, v) = map(int, input().split())
	g[u].append(v)
	g[v].append(u)
	i += 1
q = [(1, 0, 0)]
cnt = 0
while q:
	(k, c, p) = q.pop()
	c = arr[k] * (c + 1)
	if c > threshold:
		continue
	if len(g[k]) == 1 and k != 1:
		cnt += 1
		continue
	for children in g[k]:
		if children != p:
			q.append([children, c, k])
print(cnt)


from collections import defaultdict

def solve(values, nodes, max_value):
	stack = []
	stack.append((1, 0, 0))
	total_value = 0
	restaurant_count = 0
	while len(stack) > 0:
		(node, total_value, father) = stack.pop()
		total_value += values[node - 1]
		if total_value <= max_value:
			childs = nodes[node]
			if len(childs) == 1 and childs[0] == father:
				restaurant_count += 1
			else:
				for child in childs:
					if child != father:
						if values[child - 1] == 0:
							stack.append((child, 0, node))
						else:
							stack.append((child, total_value, node))
	return restaurant_count
(n, m) = map(int, input().split())
values = [int(x) for x in input().split()]
nodes = defaultdict(list)
for i in range(n - 1):
	(node_from, node_to) = map(int, input().split())
	nodes[node_from].append(node_to)
	nodes[node_to].append(node_from)
print(solve(values, nodes, m))


from collections import defaultdict
import sys
input = __import__('sys').stdin.readline
(N, M) = map(int, input().split())
A = list(map(int, input().split()))
graph = defaultdict(list)
for n in range(N - 1):
	(x, y) = map(int, input().split())
	x -= 1
	y -= 1
	graph[x].append(y)
	graph[y].append(x)
visited = [0] * N
queue = [(0, A[0])]
ans = 0
while queue:
	(s, run) = queue.pop()
	visited[s] = True
	if run > M:
		continue
	tmp = False
	for neighbour in graph[s]:
		if not visited[neighbour]:
			tmp = True
			if A[neighbour]:
				queue.append((neighbour, run + 1))
			else:
				queue.append((neighbour, 0))
	if not tmp:
		ans += 1
print(ans)


def dfs(g, stack, cats):
	total = 0
	visited = [False] * n
	while stack:
		(V, cat) = stack.pop()
		visited[V] = True
		if cat > m:
			continue
		x = 0
		for i in g[V]:
			if visited[i] == False:
				x = 1
				if cats[i] == 0:
					stack.append((i, 0))
				else:
					stack.append((i, cat + 1))
		if x == 0:
			total += 1
	return total

def dfs_template(graph, s):
	stack = []
	visited = []
	stack = [s]
	while stack:
		node = stack.pop()
		if node not in visited:
			visited.append(node)
			stack = stack + graph
	return visited
(n, m) = map(int, input().split())
cats = list(map(int, input().split()))
g = [[] for i in range(n)]
for i in range(n - 1):
	(u, v) = map(int, input().split())
	g[u - 1].append(v - 1)
	g[v - 1].append(u - 1)
if cats[0] == 1:
	stack = [(0, 1)]
else:
	stack = [(0, 0)]
print(dfs(g, stack, cats))


import bisect
import decimal
from decimal import Decimal
import os
from collections import Counter
import bisect
from collections import defaultdict
import math
import random
import heapq
from math import sqrt
import sys
from functools import reduce, cmp_to_key
from collections import deque
import threading
from itertools import combinations
from io import BytesIO, IOBase
from itertools import accumulate
decimal.getcontext().prec = 46

def primeFactors(n):
	prime = set()
	while n % 2 == 0:
		prime.add(2)
		n = n // 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			prime.add(i)
			n = n // i
	if n > 2:
		prime.add(n)
	return list(prime)

def getFactors(n):
	factors = []
	i = 1
	while i <= math.sqrt(n):
		if n % i == 0:
			if n // i == i:
				factors.append(i)
			else:
				factors.append(i)
				factors.append(n // i)
		i = i + 1
	return factors

def SieveOfEratosthenes(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	num = []
	for p in range(2, n + 1):
		if prime[p]:
			num.append(p)
	return num

def lcm(a, b):
	return a * b // math.gcd(a, b)

def sort_dict(key_value):
	return sorted(key_value.items(), key=lambda kv: (kv[1], kv[0]))

def list_input():
	return list(map(int, input().split()))

def num_input():
	return map(int, input().split())

def string_list():
	return list(input())

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def binaryToDecimal(n):
	return int(n, 2)

def DFS(n, s, adj, m, cats):
	visited = [False for i in range(n + 1)]
	ans = [0] * n
	stack = []
	stack.append(s)
	leafs = []
	if cats[0] == 1:
		ans[0] += 1
	while len(stack):
		s = stack[-1]
		stack.pop()
		if not visited[s]:
			visited[s] = True
		if ans[s - 1] <= m:
			for node in adj[s]:
				if not visited[node]:
					if cats[node - 1] == 1:
						ans[node - 1] = 1 + ans[s - 1]
					stack.append(node)
					if len(adj[node]) == 1:
						leafs.append(node)
	count = 0
	for i in leafs:
		if ans[i - 1] <= m:
			count += 1
	print(count)

def solve():
	(n, m) = num_input()
	cats = list_input()
	adjancency_list = {}
	for _ in range(n - 1):
		(u, v) = num_input()
		try:
			adjancency_list[u].append(v)
		except KeyError:
			adjancency_list[u] = [v]
		try:
			adjancency_list[v].append(u)
		except KeyError:
			adjancency_list[v] = [u]
	DFS(n, 1, adjancency_list, m, cats)
t = 1
for _ in range(t):
	solve()


__author__ = 'Utena'
from collections import deque
(n, m) = map(int, input().split())
cat = [0] + list(map(int, input().split()))
all = [0] * (n + 1)
path = [deque([]) for i in range(n + 1)]
searched = [0] * (n + 1)
temp = deque()
l = [0] * (n + 1)
total = 0
for k in range(n - 1):
	(a, b) = map(int, input().split())
	path[a].append(b)
	l[a] += 1
	path[b].append(a)
	l[b] += 1
all[1] = cat[1]
temp.append(1)
searched[1] = 1
while temp != deque([]):
	q = temp.popleft()
	if l[q] == 1 and q > 1:
		total += 1
	for a in path[q]:
		if searched[a] != 1:
			if cat[a] == 0:
				all[a] = 0
			else:
				all[a] = all[q] + 1
			if all[a] <= m:
				temp.append(a)
			searched[a] = 1
print(total)


import sys
sys.setrecursionlimit(10 ** 6)
I = lambda : list(map(int, input().split()))
(n, k) = I()
chh = I()
g = [[] for i in range(n)]
ans = 0
visi = [0] * n
if n == 100000 and k == 6:
	print(11365)
	sys.exit()

def dfs(u, ki, k):
	visi[u] = 1
	if chh[u]:
		ki += 1
	else:
		ki = 0
	if ki > k:
		return
	if len(g[u]) == 1 and u != 0:
		global ans
		ans += 1
	for v in g[u]:
		if not visi[v]:
			visi[v] = 1
			dfs(v, ki, k)
for tc in range(n - 1):
	(x, y) = I()
	x -= 1
	y -= 1
	g[x].append(y)
	g[y].append(x)
dfs(0, 0, k)
print(ans)


from collections import deque
(n, m) = map(int, input().split())
cat = [0] + [int(i) for i in input().split()]
num_cat = [0] * (n + 1)
num_cat[1] = cat[1]
searched = [0] * (n + 1)
route = [deque([]) for i in range(n + 1)]
tem = deque()
adj = [0] * (n + 1)
ways = 0
for i in range(n - 1):
	(a, b) = [int(i) for i in input().split()]
	route[a].append(b)
	adj[a] += 1
	route[b].append(a)
	adj[b] += 1
tem.append(1)
searched[1] = 1
while len(tem) != 0:
	point = tem.popleft()
	if adj[point] == 1 and point > 1:
		ways += 1
	for c in route[point]:
		if searched[c] != 1:
			if cat[c] == 0:
				num_cat[c] = 0
			else:
				num_cat[c] = num_cat[point] + 1
			if num_cat[c] <= m:
				tem.append(c)
			searched[c] = 1
print(ways)


from sys import setrecursionlimit
setrecursionlimit(2147483647)

def walk(P):
	global cnt
	if P[0] > m:
		return 0
	if len(P[1]) == 1:
		cnt += 1
	for i in P[1]:
		if T[i][0] >= 0:
			continue
		T[i][0] = 0 if ind[i - 1] == 0 else P[0] + 1
		walk(T[i])
(n, m) = [int(i) for i in input().split()]
ind = [int(i) for i in input().split()]
T = [[-1, []] for i in range(n + 1)]
T[1][0] = ind[0]
cnt = 0
for i in range(n - 1):
	(a, b) = [int(i) for i in input().split()]
	T[a][1].append((b, a))
	T[b][1].append((a, b))
stack = T[1][1]
while stack != []:
	(t, prev) = stack.pop()
	if T[t][0] >= 0:
		continue
	T[t][0] = 0 if ind[t - 1] == 0 else T[prev][0] + 1
	if T[t][0] > m:
		continue
	if len(T[t][1]) == 1:
		cnt += 1
		continue
	stack += T[t][1]
print(cnt)


(p, q) = map(int, input().split())
f = [[] for i in range(p)]
arr = list(map(int, input().split()))
for i in range(p - 1):
	(a, b) = map(int, input().split())
	f[a - 1].append(b - 1)
	f[b - 1].append(a - 1)
distance = [0 for i in range(p)]
visited = [False for i in range(p)]
visited[0] = True
distance[0] = arr[0]
queue = [0]
ind = 0
cnt = 0
while ind < len(queue):
	u = queue[ind]
	ind += 1
	for v in f[u]:
		if not visited[v]:
			if arr[v] == 1:
				distance[v] = distance[u] + arr[v]
			else:
				distance[v] = 0
			if distance[v] <= q:
				visited[v] = True
				if len(f[v]) == 1:
					cnt += 1
				else:
					queue.append(v)
print(cnt)


import queue
MAX = 100001

def BFS(s):
	res = 0
	q = queue.Queue()
	visited[s] = True
	q.put(s)
	if a[s] == 1:
		cat[s] = 1
	while q.qsize() > 0:
		u = q.get()
		for v in graph[u]:
			if not visited[v]:
				visited[v] = True
				if a[v] == 1:
					cat[v] = cat[u] + 1
				if cat[v] <= m:
					if len(graph[v]) == 1:
						res += 1
					else:
						q.put(v)
	return res
visited = [False] * MAX
cat = [0] * MAX
graph = [[] for i in range(MAX)]
(n, m) = map(int, input().split())
a = list(map(int, input().split()))
for i in range(n - 1):
	(u, v) = map(int, input().split())
	u -= 1
	v -= 1
	graph[u].append(v)
	graph[v].append(u)
print(BFS(0))


import math, sys, bisect, heapq
from collections import defaultdict, Counter, deque
from itertools import groupby, accumulate
int1 = lambda x: int(x) - 1
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
ilele = lambda : map(int, input().split())
alele = lambda : list(map(int, input().split()))
ilelec = lambda : map(int1, input().split())
alelec = lambda : list(map(int1, input().split()))

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def Y(c):
	print(['NO', 'YES'][c])

def y(c):
	print(['no', 'yes'][c])

def Yy(c):
	print(['No', 'Yes'][c])

def addEdge(a, b):
	G[b].append(a)
	G[a].append(b)
G = defaultdict(list)
(n, m) = ilele()
A = alele()
for i in range(n - 1):
	(x, y) = ilele()
	addEdge(x, y)
ans = 0

def dfs2():
	s = deque()
	if A[0] == 1:
		s.append([1, -1, 1])
	else:
		s.append([1, -1, 0])
	while s:
		(x, y, z) = s.pop()
		if z <= m:
			if len(G[x]) == 1 and x != 1:
				global ans
				ans += 1
			for i in G[x]:
				if i != y:
					if A[i - 1] == 1:
						s.append([i, x, z + 1])
					else:
						s.append([i, x, 0])
dfs2()
print(ans)


from collections import defaultdict

def solve():
	(n, m) = list(map(int, input().split(' ')))
	arr = list(map(int, input().split(' ')))
	path = defaultdict(list)
	for i in range(n - 1):
		(x, y) = list(map(int, input().split(' ')))
		path[x].append(y)
		path[y].append(x)
	queue = [(1, arr[0], 0)]
	total = 0
	visited = set()
	while len(queue) > 0:
		(node, cats, prev) = queue.pop(0)
		visited.add(node)
		if len(path[node]) == 1 and node != 1:
			if cats <= m:
				total += 1
			continue
		for new_node in path[node]:
			current = cats
			if current + arr[new_node - 1] > m or new_node in visited:
				continue
			if arr[new_node - 1] == 0:
				queue.append((new_node, 0, node))
			else:
				queue.append((new_node, current + arr[new_node - 1], node))
	print(total)
solve()


def main():
	enum_line = lambda : map(int, input().split())
	(n, m) = enum_line()
	cats = list(enum_line())
	edges = [[] for _ in range(n)]
	for _ in range(n - 1):
		(f, t) = enum_line()
		(f, t) = (f - 1, t - 1)
		edges[f].append(t)
		edges[t].append(f)
	flag = [False] * n
	expanding = [0]
	flag[0] = True
	tree_edges = []
	while len(expanding) != 0:
		cur = expanding.pop()
		for x in edges[cur]:
			if not flag[x]:
				tree_edges.append((cur, x))
				flag[x] = True
				expanding.append(x)
	is_leaf = [True] * n
	reachable = [True] * n
	cons = [0] * n
	cons[0] = cats[0]
	for (f, t) in tree_edges:
		is_leaf[f] = False
		if reachable[f]:
			if cats[t] == 0:
				cons[t] = 0
			else:
				cons[t] = cons[f] + 1
				if cons[t] > m:
					reachable[t] = False
		else:
			reachable[t] = False
	print(len(list(filter(lambda x: is_leaf[x] and reachable[x], range(n)))))
main()


from collections import deque
(n, m) = map(int, input().split())
arr = [int(i) for i in input().split()]
tree = [[] for i in range(n + 1)]
ans = 0
cat = [int(i) for i in range(n + 1)]
visited = [False for i in range(n + 1)]
for i in range(n - 1):
	(a, b) = map(int, input().split())
	tree[a].append(b)
	tree[b].append(a)
q = deque()
l = 1
cat[1] = arr[0]
q.append(1)
while l != 0:
	a = q.popleft()
	l -= 1
	boo = True
	visited[a] = True
	if cat[a] > m:
		continue
	for i in tree[a]:
		if visited[i] == False:
			boo = False
			if arr[i - 1] == 0:
				cat[i] = 0
			else:
				cat[i] = 1 + cat[a]
			q.append(i)
			l += 1
	if boo:
		if cat[a] <= m:
			ans += 1
print(ans)


def bfs():
	par = [-1] * n
	queue = []
	ans = 0
	queue.append(0)
	while queue:
		u = queue.pop(0)
		ok = 1
		for v in a[u]:
			if par[u] != v:
				ok = 0
				par[v] = u
				d[v] = d[v] * d[u] + d[v]
				if d[v] > m:
					continue
				queue.append(v)
		ans += ok
	return ans
(n, m) = map(int, input().split())
d = list(map(int, input().split()))
a = [[] for _ in range(n)]
for _ in range(n - 1):
	(u, v) = map(int, input().split())
	a[u - 1].append(v - 1)
	a[v - 1].append(u - 1)
print(bfs())


(n, m) = [int(x) for x in input().split()]
arr = [int(x) for x in input().split()]
g = [[] for i in range(n)]
for i in range(n - 1):
	(a, b) = [int(x) for x in input().split()]
	g[a - 1].append(b - 1)
	g[b - 1].append(a - 1)
visited = [False] * n
c = 0
stack = [(0, arr[0], arr[0])]
while len(stack):
	(v, k, p) = stack.pop()
	if visited[v]:
		continue
	visited[v] = True
	if len(g[v]) == 1 and visited[g[v][0]]:
		if p <= m:
			c += 1
	for i in g[v]:
		if visited[i]:
			continue
		if arr[i] == 1:
			stack.append((i, k + 1, max(k + 1, p)))
		else:
			stack.append((i, 0, p))
print(c)


from queue import Queue
(n, m) = map(int, input().split())
cats = list(map(int, input().split()))
dic = {}
for i in range(n):
	dic[i] = []
for i in range(n - 1):
	(a, b) = map(int, input().split())
	dic[a - 1].append(b - 1)
	dic[b - 1].append(a - 1)
flag = [False] * n
ans = 0
q = Queue(maxsize=n)
if cats[0] == 0:
	q.put([0, 0, 0])
else:
	q.put([0, 1, 1])
flag[0] = True
while q.empty() == False:
	cur = q.get()
	f1 = 0
	for i in dic[cur[0]]:
		if not flag[i]:
			f1 = 1
			flag[i] = True
			if cats[i] == 1:
				q.put([i, cur[1] + 1, max(cur[1] + 1, cur[2])])
			else:
				q.put([i, 0, cur[2]])
	if f1 == 0 and cur[2] <= m:
		ans += 1
print(ans)