import java.util.*;

public class C {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);

        int n = in.nextInt();
        int m = in.nextInt();

        Node[] node = new Node[n];
        for (int i = 0; i < n; i++) {
            node[i] = new Node( in.nextInt() );
        }

        for (int i = 0; i < n - 1; i++) {
            int f = in.nextInt() - 1;
            int t = in.nextInt() - 1;
            node[f].adjacent.add(node[t]);
        }

        System.out.println( C.dfs(node[0], 0, m) );

    }

    public static int dfs(Node n, int c, int m) {
        if (n.c == 1) {
            if (++c > m) return 0;
        } else {
            c = 0;
        }
        if (n.adjacent.size() == 0) {
            return 1;
        }
        int tot_rest = 0;
        for (Node a : n.adjacent) {
            if (a == n) continue;
            tot_rest += dfs(a, c, m);
        }
        return tot_rest;
    }

    public static class Node {
        int c;
        ArrayList<Node> adjacent;
        public Node(int c) {
            this.adjacent = new ArrayList<Node>();
            this.c = c;
        }
    }
}


import java.util.*;

public class C {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);

        int n = in.nextInt();
        int m = in.nextInt();

        int[] cats = new int[n];
        for (int i = 0; i < n; i++) {
            cats[i] = in.nextInt();
        }

        Graph g = new Graph(n, m, cats);

        for (int i = 0; i < n - 1; i++) {
            g.add(in.nextInt(), in.nextInt());
        }

        g.go();

        System.out.println( g.cnt );

    }

}

class Graph {

    int cnt;
    private int n, m;
    private int[] cats;
    private ArrayList<ArrayList<Integer>> adj;

    public Graph(int n, int m, int[] cats) {
        this.cnt = 0;
        this.n = n;
        this.m = m;
        this.cats = cats;
        this.adj = new ArrayList<ArrayList<Integer>>(n);
        for (int i = 0; i < n; i++) {
            this.adj.add(new ArrayList<Integer>());
        }
    }

    public void add(int i, int j) {
        this.adj.get(i - 1).add(j - 1);
        this.adj.get(j - 1).add(i - 1);
    }

    public void go() {
        dfs(0, 0, new boolean[n]);
    }

    private void dfs(int i, int c, boolean[] visited) {
        visited[i] = true;
        if (cats[i] == 1) {
            if (++c > m) return;
        } else {
            c = 0;
        }
        boolean isLeaf = true;
        for (int next : adj.get(i)) {
            if (!visited[next]) {
                dfs(next, c, visited);
                isLeaf = false;
            }
        }
        if (isLeaf) cnt++;
    }

}


import java.util.*;

public class C {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);

        int n = in.nextInt();
        int m = in.nextInt();

        int[] cats = new int[n];
        for (int i = 0; i < n; i++) {
            cats[i] = in.nextInt();
        }

        Graph g = new Graph(n, m, cats);

        for (int i = 0; i < n - 1; i++) {
            g.add(in.nextInt(), in.nextInt());
        }

        g.go();

        System.out.println(g.max);

    }
}

class Graph {
    int max;
    int n, m;
    int[] cats;
    ArrayList<ArrayList<Integer>> adj;
    public Graph(int n, int m, int[] cats) {
        this.n = n;
        this.m = m;
        this.cats = cats;
        adj = new ArrayList<ArrayList<Integer>>(n);
        for (int i = 0; i < n; i++) {
            adj.add(i, new ArrayList<Integer>());
        }
    }
    public void add(int x, int y) {
        x--;
        y--;
        adj.get(x).add(y);
        adj.get(y).add(x);
    }
    public void go() {
        boolean[] seen = new boolean[n];
        max = dfs(0, 0, seen);
    }
    private int dfs(int i, int consec_cats, boolean[] seen) {
        seen[i] = true;
        if (cats[i] == 0) consec_cats = 0;
        else {
            consec_cats++;
            if (consec_cats > m) {
                return 0;
            }
        }
        int num_res = 0;
        boolean isRest = true;
        for (Integer j : adj.get(i)) {
            if (!seen[j]) {
                num_res += dfs(j, consec_cats, seen);
                isRest = false;
            }
        }
        if (isRest) num_res++;
        return num_res;
    }

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.StringTokenizer;

public class Main {
static class FastScanner {

BufferedReader reader;
StringTokenizer tokenizer;

public FastScanner(InputStream stream) {
this.reader = new BufferedReader(new InputStreamReader(stream));
}

public int nextInt() throws IOException {
return Integer.parseInt(next());
}

public int[] nextIntegerArray(int n) throws IOException {
int[] a = new int[n];
for (int i = 0; i < a.length; i++) {
a[i] = nextInt();
}
return a;
}

public long[] nextLongArray(int n) throws IOException {
long[] a = new long[n];
for (int i = 0; i < a.length; i++) {
a[i] = nextLong();
}
return a;
}

public int nextInt(int radix) throws IOException {
return Integer.parseInt(next(), radix);
}

public long nextLong() throws IOException {
return Long.parseLong(next());
}

public long nextLong(int radix) throws IOException {
return Long.parseLong(next(), radix);
}

public double nextDouble() throws IOException {
return Double.parseDouble(next());
}

public BigInteger nextBigInteger() throws IOException {
return new BigInteger(next());
}

public BigInteger nextBigInteger(int radix) throws IOException {
return new BigInteger(next(), radix);
}

public String next() throws IOException {
if (tokenizer == null || !tokenizer.hasMoreTokens()) {
tokenizer = new StringTokenizer(reader.readLine());
return this.next();
}
return tokenizer.nextToken();
}

public void close() throws IOException {
this.reader.close();
}
}

                   //SOLUTION //

	FastScanner in = new FastScanner(System.in);
	PrintWriter out = new PrintWriter(System.out);

	public static void main(String[] args) throws IOException{
    new Main().solve();
    }//void main

	void solve() throws IOException{
		 int n = in.nextInt(), m = in.nextInt();
		 int[] a = new int[n];
		 int[] count = new int[n];
		 int res=0;
		 for(int i = 0; i < n; i++)
			 a[i] = in.nextInt();
		 int la,lb;
		 boolean[][] rel = new boolean[n][n];
		 for(int i = 0; i < n-1; i++){
			 la = in.nextInt()-1;
			 lb = in.nextInt()-1;
			 rel[la][lb]=true;
			 count[la]++;
			 if(a[la] > 0 && a[lb] > 0)
			 a[lb]=a[la]+a[lb];
			 if(a[la]>m)
				 a[lb]=m+1;
		 }
		 for(int i = 0; i < n; i++){
			 //out.print(a[i]+" ");
			 if(a[i] <= m && count[i] == 0)
				 res++;
		 }
		 //out.println();
		 out.println(res);
		 in.close();
	     out.flush();
		 out.close();
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.StringTokenizer;

public class Main {
	               //SOLUTION //
    FastScanner in = new FastScanner(System.in);
	PrintWriter out = new PrintWriter(System.out);
    //
	static int n,m;
    static int[] cats;
    static ArrayList<Integer> op[];
    static int ans=0;

	public static void main(String[] args) throws IOException{
    new Main().solve();
    }//void main
	void dfs(int source,int prev,int cat,int add){
		if(cats[source]==1) cat++;
		else{
			cat=0;
		}
		if(cat>m)add=0;
		boolean check=true;
		for(int i = 0; i < op[source].size(); i++){
			int get = op[source].get(i);
			//if(get==prev)continue;
			check = false;
			dfs(get,source,cat,add);
		}
			if(check)ans+=add;

	}
	void solve() throws IOException{
         n = in.nextInt();
         m = in.nextInt();
         cats = new int[n+1];
         for(int i = 1; i <= n; i++) cats[i] = in.nextInt();
         op = new  ArrayList[n+1];
         for(int i = 1; i <= n; i++)
        	 op[i] = new ArrayList<>();
         for(int i = 1; i <= n-1; i++){
        	 int la = in.nextInt();
        	 int lb = in.nextInt();
        	 op[la].add(lb);
        	 //op[lb].add(la);
         }
         dfs(1,1,0,1);
         out.println(ans);
		 in.close();
	     out.flush();
		 out.close();
	}
}

class FastScanner {

BufferedReader reader;
StringTokenizer tokenizer;

public FastScanner(InputStream stream) {
this.reader = new BufferedReader(new InputStreamReader(stream));
}

public int nextInt() throws IOException {
return Integer.parseInt(next());
}

public int[] nextIntegerArray(int n) throws IOException {
int[] a = new int[n];
for (int i = 0; i < a.length; i++) {
a[i] = nextInt();
}
return a;
}

public long[] nextLongArray(int n) throws IOException {
long[] a = new long[n];
for (int i = 0; i < a.length; i++) {
a[i] = nextLong();
}
return a;
}

public int nextInt(int radix) throws IOException {
return Integer.parseInt(next(), radix);
}

public long nextLong() throws IOException {
return Long.parseLong(next());
}

public long nextLong(int radix) throws IOException {
return Long.parseLong(next(), radix);
}

public double nextDouble() throws IOException {
return Double.parseDouble(next());
}

public BigInteger nextBigInteger() throws IOException {
return new BigInteger(next());
}

public BigInteger nextBigInteger(int radix) throws IOException {
return new BigInteger(next(), radix);
}

public String next() throws IOException {
if (tokenizer == null || !tokenizer.hasMoreTokens()) {
tokenizer = new StringTokenizer(reader.readLine());
return this.next();
}
return tokenizer.nextToken();
}

public void close() throws IOException {
this.reader.close();
}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.StringTokenizer;

public class Main {
	               //SOLUTION //
    FastScanner in = new FastScanner(System.in);
	PrintWriter out = new PrintWriter(System.out);
    //
	static int n,m;
    static int[] cats;
    static ArrayList<Integer> op[];
    static int ans=0;

	public static void main(String[] args) throws IOException{
    new Main().solve();
    }//void main
	void dfs(int source,int prev,int cat,int add){
		if(cats[source]==1) cat++;
		else{
			cat=0;
		}
		if(cat>m)add=0;
		boolean check=true;
		for(int i = 0; i < op[source].size(); i++){
			int get = op[source].get(i);
			if(get==prev)continue;
			check = false;
			dfs(get,source,cat,add);
		}
			if(check)ans+=add;

	}
	void solve() throws IOException{
         n = in.nextInt();
         m = in.nextInt();
         cats = new int[n+1];
         for(int i = 1; i <= n; i++) cats[i] = in.nextInt();
         op = new  ArrayList[n+1];
         for(int i = 1; i <= n; i++)
        	 op[i] = new ArrayList<>();
         for(int i = 1; i <= n-1; i++){
        	 int la = in.nextInt();
        	 int lb = in.nextInt();
        	 op[la].add(lb);
        	 op[lb].add(la);
         }
         dfs(1,1,0,1);
         out.println(ans);
		 in.close();
	     out.flush();
		 out.close();
	}
}

class FastScanner {

BufferedReader reader;
StringTokenizer tokenizer;

public FastScanner(InputStream stream) {
this.reader = new BufferedReader(new InputStreamReader(stream));
}

public int nextInt() throws IOException {
return Integer.parseInt(next());
}

public int[] nextIntegerArray(int n) throws IOException {
int[] a = new int[n];
for (int i = 0; i < a.length; i++) {
a[i] = nextInt();
}
return a;
}

public long[] nextLongArray(int n) throws IOException {
long[] a = new long[n];
for (int i = 0; i < a.length; i++) {
a[i] = nextLong();
}
return a;
}

public int nextInt(int radix) throws IOException {
return Integer.parseInt(next(), radix);
}

public long nextLong() throws IOException {
return Long.parseLong(next());
}

public long nextLong(int radix) throws IOException {
return Long.parseLong(next(), radix);
}

public double nextDouble() throws IOException {
return Double.parseDouble(next());
}

public BigInteger nextBigInteger() throws IOException {
return new BigInteger(next());
}

public BigInteger nextBigInteger(int radix) throws IOException {
return new BigInteger(next(), radix);
}

public String next() throws IOException {
if (tokenizer == null || !tokenizer.hasMoreTokens()) {
tokenizer = new StringTokenizer(reader.readLine());
return this.next();
}
return tokenizer.nextToken();
}

public void close() throws IOException {
this.reader.close();
}
}


import java.io.*;
import java.util.*;
public class KefaandPark
{
    static int m, total;
    static ArrayList<Vertice> park;
    static class Vertice{
        int ind;
        boolean cats;
        boolean leaf;
        ArrayList<Integer> children;

        public Vertice(int i, int c){
            ind = i;
            cats = c == 1 ? true:false;
            children = new ArrayList<Integer>();
        }
    }
    static void avoidCats(int i, boolean there, int limit){
        if(limit > m) return;
        int ind;
        if(park.get(i).leaf){
            total++;
            return;
        }
        for (int j = 0; j < park.get(i).children.size(); j++) {
            ind = park.get(i).children.get(j);
            if(park.get(ind).cats)
                avoidCats(ind, true, limit+1);
            else
                avoidCats(ind, false, 0);
        }
    }
    public static void main(String[] args) throws IOException
    {
        //Locale.setDefault (Locale.US);
        Reader in = new Reader();
        StringBuilder out = new StringBuilder();
        park = new ArrayList<Vertice>();
        int n, a, b;

        for (int i = 0; i < 1; i++) {
            n = in.nextInt();
            m = in.nextInt();
            park.clear();
            for (int j = 1; j <= n; j++)
                park.add(new Vertice(j, in.nextInt()));

            for (int j = 0; j < n-1; j++)
                park.get(in.nextInt()-1).children.add(in.nextInt()-1);

            for (int j = 0; j < park.size(); j++) {
                if(park.get(j).children.size() == 0)
                    park.get(j).leaf = true;
                else
                    park.get(j).leaf = false;
            }

            total = 0;
            if(park.get(0).cats)
                avoidCats(0, true, 1);
            else
                avoidCats(0, false, 0);

            System.out.println(total);
        }

//        int left, right;
//        left = 1;
//        for (int i = 1; i <= 100000; i++) {
//            out.append("0 ");
//        }
//        System.out.println(out);
    }
    static class  Reader
    {
        BufferedReader br;
        StringTokenizer st;
        Reader() { // To read from the standard input
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        Reader(int i) throws IOException { // To read from a file
            br = new BufferedReader(new FileReader("Sample Input.txt"));
        }
       String next() throws IOException {
          while (st == null || !st.hasMoreTokens())
             st = new StringTokenizer(br.readLine());
          return st.nextToken();
       }
       int nextInt() throws IOException { return Integer.parseInt(next()); }
       long nextLong() throws IOException { return Long.parseLong(next()); }
       double nextDouble() throws IOException { return Double.parseDouble(next()); }
       String nextLine() throws IOException { return br.readLine(); }
    }

}


import java.io.*;
import java.util.*;
public class KefaandPark
{
    static int m, total;
    static ArrayList<Vertice> park;
    static boolean[] visited;
    static class Vertice{
        int ind;
        boolean cats;
        boolean leaf;
        ArrayList<Integer> edges;

        public Vertice(int i, int c){
            ind = i;
            cats = c == 1 ? true:false;
            edges = new ArrayList<Integer>();
        }
    }
    static void avoidCats(int i, int limit){
        if(limit > m || visited[i]) return;
        visited[i] = true;
        int ind;
        if(park.get(i).leaf){
            total++;
            return;
        }
        for (int j = 0; j < park.get(i).edges.size(); j++) {
            ind = park.get(i).edges.get(j);
            if(park.get(ind).cats)
                avoidCats(ind, limit+1);
            else
                avoidCats(ind, 0);
        }
    }
    public static void main(String[] args) throws IOException
    {
        Reader in = new Reader();
        park = new ArrayList<Vertice>();
        int n, a, b;

        for (int i = 0; i < 1; i++) {
            n = in.nextInt();
            m = in.nextInt();
            park.clear();
            for (int j = 1; j <= n; j++)
               park.add(new Vertice(j, in.nextInt()));

            for (int j = 0; j < n-1; j++) {
                a = in.nextInt()-1;
                b = in.nextInt()-1;
                park.get(a).edges.add(b);
                park.get(b).edges.add(a);
            }

            for (int j = 1; j < park.size(); j++) {
                if(park.get(j).edges.size() == 1)
                    park.get(j).leaf = true;
                else
                    park.get(j).leaf = false;
            }

            visited = new boolean[n];
            total = 0;
            if(park.get(0).cats)
                avoidCats(0, 1);
            else
                avoidCats(0, 0);

            System.out.println(total);
        }

//        int left, right;
//        left = 1;
//        for (int i = 1; i <= 100000; i++) {
//            out.append("0 ");
//        }
//        System.out.println(out);
    }
    static class  Reader
    {
        BufferedReader br;
        StringTokenizer st;
        Reader() { // To read from the standard input
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        Reader(int i) throws IOException { // To read from a file
            br = new BufferedReader(new FileReader("Sample Input.txt"));
        }
       String next() throws IOException {
          while (st == null || !st.hasMoreTokens())
             st = new StringTokenizer(br.readLine());
          return st.nextToken();
       }
       int nextInt() throws IOException { return Integer.parseInt(next()); }
       long nextLong() throws IOException { return Long.parseLong(next()); }
       double nextDouble() throws IOException { return Double.parseDouble(next()); }
       String nextLine() throws IOException { return br.readLine(); }
    }

}


import java.io.*;
import java.util.*;

public class Program {

    BufferedReader br;
    PrintWriter out;
    StringTokenizer st;
    boolean eof;

    static final int Mod = 1000000007;
    static final double inf = 10000000000.0;

    @SuppressWarnings("unchecked")
	void solve() throws IOException {
    	int n, m, ans;
		int x, y, a[], v[], c[];
    	n = nextInt();
    	m = nextInt();
    	ans = 0;
    	a = new int[n+1];
    	v = new int[n+1];
    	c = new int[n+1];
    	ArrayList<Integer>[] t = new ArrayList[n+1];
    	for(int i = 1; i <= n; i++)
    	{
    		a[i] = nextInt();
    		t[i] = new ArrayList<>();
    	}
    	for(int i = 0; i < n-1; i++)
    	{
    		x = nextInt();
    		y = nextInt();
    		t[x].add(y);
    	}
    	Stack<Integer> stack = new Stack<>();
    	stack.push(1);
    	v[1] = 1;
    	if (a[1] == 1)
    		c[1]++;
    	while(!stack.isEmpty())
    	{
    		int q = stack.peek();
    		boolean pass = false;
    		if (c[q] > m)
    		{
    			stack.pop();
    			continue;
    		}
    		for(int e : t[q])
    			if (v[e] == 0)
	    		{
	    			stack.push(e);
	    			v[e] = 1;
	    			pass = true;
	    			if (a[e] == 1)
	    				c[e] = c[q]+1;
	    			break;
	    		}
    		if (!pass)
    		{
    			if (c[q] <= m && t[q].size() == 0)
    				ans++;
    			stack.pop();
    		}
    	}
    	out.println(ans);
    }

    Program() throws IOException {
        br = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        solve();
        out.close();
    }

    public static void main(String[] args) throws IOException {
        new Program();
    }

    String nextToken() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (Exception e) {
                eof = true;
                return null;
            }
        }
        return st.nextToken();
    }

    String nextString() {
        try {
            return br.readLine();
        } catch (IOException e) {
            eof = true;
            return null;
        }
    }

    int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }
}


import java.io.*;
import java.util.*;

public class Program {

    BufferedReader br;
    PrintWriter out;
    StringTokenizer st;
    boolean eof;

    static final int Mod = 1000000007;
    static final double inf = 10000000000.0;

    @SuppressWarnings("unchecked")
	void solve() throws IOException {
    	int n, m, ans;
		int x, y, a[], v[], c[], b[];
    	n = nextInt();
    	m = nextInt();
    	ans = 0;
    	a = new int[n+1];
    	v = new int[n+1];
    	c = new int[n+1];
    	b = new int[n+1];
    	ArrayList<Integer>[] t = new ArrayList[n+1];
    	for(int i = 1; i <= n; i++)
    	{
    		a[i] = nextInt();
    		t[i] = new ArrayList<>();
    	}
    	for(int i = 0; i < n-1; i++)
    	{
    		x = nextInt();
    		y = nextInt();
    		t[x].add(y);
    		t[y].add(x);
    	}
    	Stack<Integer> stack = new Stack<>();
    	stack.push(1);
    	v[1] = 1;
    	if (a[1] == 1)
    		c[1]++;
    	while(!stack.isEmpty())
    	{
    		int q = stack.peek();
    		boolean pass = false;
    		if (c[q] > m)
    		{
    			stack.pop();
    			continue;
    		}
    		for(int e : t[q])
    			if (v[e] == 0)
	    		{
	    			stack.push(e);
	    			b[q] = 1;
	    			v[e] = 1;
	    			pass = true;
	    			if (a[e] == 1)
	    				c[e] = c[q]+1;
	    			break;
	    		}
    		if (!pass)
    		{
    			if (c[q] <= m && b[q] == 0)
    				ans++;
    			stack.pop();
    		}
    	}
    	out.println(ans);
    }

    Program() throws IOException {
        br = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        solve();
        out.close();
    }

    public static void main(String[] args) throws IOException {
        new Program();
    }

    String nextToken() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (Exception e) {
                eof = true;
                return null;
            }
        }
        return st.nextToken();
    }

    String nextString() {
        try {
            return br.readLine();
        } catch (IOException e) {
            eof = true;
            return null;
        }
    }

    int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }
}


import java.io.*;
import java.util.*;

public class Program {

    BufferedReader br;
    PrintWriter out;
    StringTokenizer st;
    boolean eof;

    static final int MOD = 1000000007;
    static final double INF = 10000000000.0;

	int n, m, c[], h[], edgeno = 0;
	int x, y;
	Edge e[];

	class Edge
	{
		int to, next;
	};

	void addEdge(int x, int y)
	{
		e[edgeno] = new Edge();
		e[edgeno].to = y;
		e[edgeno].next = h[x];
		h[x] = edgeno++;
	}

	int dfs(int x, int y, int cur)
	{
		int leaf = 1, res = 0;
		int ncur = c[x] != 0 ? cur + 1 : 0;
		if (ncur > m)
			return 0;
		for(int i = h[x]; i != -1; i = e[i].next)
		{
			int v = e[i].to;
			if (v == y) continue;
			leaf = 0;
			res += dfs(v, x, ncur);
		}
		return leaf + res;
	}

	void solve() throws IOException {
		n = nextInt();
		m = nextInt();
		c = new int[n+1];
		h = new int[n+1];
		e = new Edge[2 * n + 2];
		for(int i = 1; i <= n; i++)
		{
			c[i] = nextInt();
			h[i] = -1;
		}
		for(int i = 1; i < n; i++)
		{
			x = nextInt();
			y = nextInt();
			addEdge(x, y);
			addEdge(y, x);
		}
		out.println(dfs(1, 0, 0));
    }

    Program() throws IOException {
        br = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        solve();
        out.close();
    }

    public static void main(String[] args) throws IOException {
        new Program();
    }

    String nextToken() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (Exception e) {
                eof = true;
                return null;
            }
        }
        return st.nextToken();
    }

    String nextString() {
        try {
            return br.readLine();
        } catch (IOException e) {
            eof = true;
            return null;
        }
    }

    int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Comparator;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) {
		InputStream input = System.in;
		OutputStream output = System.out;
		InputReader in = new InputReader(input);
		PrintWriter out = new PrintWriter(output);
		Solve solve = new Solve();
		solve.solve(in, out);
		out.close();
	}

	static class Solve {
		void solve(InputReader in, PrintWriter out) {
			int n = in.nextInt();
			int t = in.nextInt();
			int[] cats = new int[n];
			for(int i = 0; i < n; ++i) {
				cats[i] = in.nextInt();
			}

			for(int i = 0; i < n-1; ++i) {
				int x = in.nextInt();
				int y = in.nextInt();
				new Branch(Math.min(x, y), Math.max(x, y));
			}

        }

		class Branch {
			int x;
			int y;
			Branch(int x, int y) {
				this.x = x;
				this.y = y;
			}
			public String toString() {
				return x + " " + y;
			}
		}
	}

	static class InputReader {
		BufferedReader br;
		StringTokenizer tokenizer = null;
		InputReader(InputStream in) {
			br = new BufferedReader(new InputStreamReader(in));
		}

		String next() {
			while((tokenizer==null)||(!(tokenizer.hasMoreTokens()))) {
				try {
					tokenizer = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return tokenizer.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

public class Main {

	static int result = 0;
	static int count = 0;
	static String[] cats;
	static int n;
	static int c;

	static Map<Integer, Set<Integer[]>> map;

    public static void main(String[] args) throws IOException {
        BufferedReader rd = new BufferedReader(new InputStreamReader(System.in));

        	String [] t = rd.readLine().split("\\s+");
        	n = Integer.parseInt(t[0]);
        	c = Integer.parseInt(t[1]);

        	cats = rd.readLine().split("\\s+");

        	map = new HashMap<Integer, Set<Integer[]>>();
        	int k = 0;
        	for(int i = 0; i < n-1; i++) {
        		String[] str = rd.readLine().split("\\s+");
        		Integer[] a = new Integer[2];
        		a[0] = Integer.parseInt(str[0]);
        		a[1] = Integer.parseInt(str[1]);
        		if (a[0]!=k) {
        			k = a[0];
        			map.put(k, new HashSet<Integer[]>());
        		}
        		map.get(k).add(a);
        	}
        	if (Integer.parseInt(cats[0])==1) {
        		count++;
        	}

        	tree(map.get(1));
        	System.out.println(result);

    }

    public static void tree(Set<Integer[]> set) {
    	for(Integer[] mas : set) {
    		int sor = count;
    		int max = count;
    		if (Integer.parseInt(cats[mas[1]-1])==1) {
    			count++;
    			if (count>max) {
    				max = count;
    			}
    		} else {
    			count = 0;
    		}

    		if (map.containsKey(mas[1])) {
    			tree(map.get(mas[1]));
    		} else {
    			if (max<=c) {
    				result++;
    			}
    		}
    		count = sor;
    	}
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class Main {

	static int result = 0;
	static int count = 0;
	static String[] cats;
	static int n;
	static int c;
	static List<Set<Integer[]>> list;

    public static void main(String[] args) throws IOException {
        BufferedReader rd = new BufferedReader(new InputStreamReader(System.in));

        	String [] t = rd.readLine().split("\\s+");
        	n = Integer.parseInt(t[0]);
        	c = Integer.parseInt(t[1]);

        	cats = rd.readLine().split("\\s+");

        	list = new ArrayList<Set<Integer[]>>();
        	int k = 0;
        	for(int i = 0; i < n-1; i++) {
        		String[] str = rd.readLine().split("\\s+");

        		Integer[] a = new Integer[2];
        		a[0] = Integer.parseInt(str[0]);
        		a[1] = Integer.parseInt(str[1]);
        		if (a[0]!=k) {
        			k = a[0];
        			list.add(new HashSet<Integer[]>());
        		}
        		list.get(k-1).add(a);
        	}
        	if (Integer.parseInt(cats[0])==1) {
        		count++;
        	}
        	tree(list.get(0));
        	System.out.println(result);

    }

    public static void tree(Set<Integer[]> set) {
    	for(Integer[] mas : set) {
    		int sor = count;
    		if (Integer.parseInt(cats[mas[1]-1])==1) {
    			count++;

    		} else {
    			if (count<=c){
    				result++;
    			}
    		}
    		if (list.size()>mas[1]-1) {
    			tree(list.get(mas[1]-1));
    		}
    		count = sor;
    	}
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

public class Main {

	static int result = 0;
	static int count = 0;
	static String[] cats;
	static int n;
	static int c;

	static Map<Integer, Set<Integer[]>> map;

    public static void main(String[] args) throws IOException {
        BufferedReader rd = new BufferedReader(new InputStreamReader(System.in));

        	String [] t = rd.readLine().split("\\s+");
        	n = Integer.parseInt(t[0]);
        	c = Integer.parseInt(t[1]);

        	cats = rd.readLine().split("\\s+");

        	map = new ConcurrentHashMap<Integer, Set<Integer[]>>();
        	for(int i = 0; i < n-1; i++) {
        		String[] str = rd.readLine().split("\\s+");
        		Integer[] a = new Integer[2];
        		a[0] = Math.min(Integer.parseInt(str[0]), Integer.parseInt(str[1]));
        		a[1] = Math.max(Integer.parseInt(str[0]), Integer.parseInt(str[1]));
        		if (!(map.containsKey(a[0]))) {
        			map.put(a[0], new HashSet<Integer[]>());
        		}
        		map.get(a[0]).add(a);
        	}

        	for(Entry<Integer, Set<Integer[]>> entry1 : map.entrySet()) {
        		boolean f = false;
        		if (entry1.getKey()==1) {
        			continue;
        		}
        		for(Entry<Integer, Set<Integer[]>> entry2 : map.entrySet()) {
        			for(Integer[] arr : entry2.getValue()){
        				if (arr[1]==entry1.getKey()){
        					f = true;
        				}
        			}
        		}
        		if (f==false) {
        			for(Integer[] arr : entry1.getValue()) {
        				Integer[] a = new Integer[2];
        				a[0] = arr[1];
        				a[1] = arr[0];
        				if (!(map.containsKey(arr[1]))) {
                			map.put(arr[1], new HashSet<Integer[]>());
                		}
        				map.get(arr[1]).add(a);
        				map.get(arr[0]).remove(arr);
        			}
        		}
        	}

//        	for(Entry<Integer, Set<Integer[]>> entry : map.entrySet()) {
//        		for(Integer[] arr : entry.getValue()){
//    				System.out.println(entry.getKey() + " " + arr[0] + " " + arr[1]);
//    			}
//        	}

        	if (Integer.parseInt(cats[0])==1) {
        		count++;
        	}

        	tree(map.get(1));
        	System.out.println(result);

    }

    public static void tree(Set<Integer[]> set) {
    	for(Integer[] mas : set) {
    		int sor = count;
    		int max = count;
    		if (Integer.parseInt(cats[mas[1]-1])==1) {
    			count++;
    			if (count>max) {
    				max = count;
    			}
    		} else {
    			count = 0;
    		}

    		if ((map.containsKey(mas[1]))&&(!(map.get(mas[1]).isEmpty()))) {
    			tree(map.get(mas[1]));
    		} else {
    			if (max<=c) {
    				result++;
    			}
    		}
    		count = sor;
    	}
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class Main {

	static int result = 0;
	static int count = 0;
	static String[] cats;
	static int n;
	static int c;
	static List<Set<Integer[]>> list;

    public static void main(String[] args) throws IOException {
        BufferedReader rd = new BufferedReader(new InputStreamReader(System.in));

        	String [] t = rd.readLine().split("\\s+");
        	n = Integer.parseInt(t[0]);
        	c = Integer.parseInt(t[1]);

        	cats = rd.readLine().split("\\s+");

        	list = new ArrayList<Set<Integer[]>>();
        	int k = 0;
        	for(int i = 0; i < n-1; i++) {
        		String[] str = rd.readLine().split("\\s+");

        		Integer[] a = new Integer[2];
        		a[0] = Integer.parseInt(str[0]);
        		a[1] = Integer.parseInt(str[1]);
        		if (a[0]!=k) {
        			k = a[0];
        			list.add(new HashSet<Integer[]>());
        		}
        		list.get(k-1).add(a);
        	}
        	if (Integer.parseInt(cats[0])==1) {
        		count++;
        	}
        	tree(list.get(0));
        	System.out.println(result);

    }

    public static void tree(Set<Integer[]> set) {
    	for(Integer[] mas : set) {
    		int sor = count;
    		if (Integer.parseInt(cats[mas[1]-1])==1) {
    			count++;
    			if (count<=c){
    				result++;
    			}
    		} else {
    			if (count<=c){
    				result++;
    			}
    		}
    		if (list.size()>mas[1]-1) {
    			tree(list.get(mas[1]-1));
    		}
    		count = sor;
    	}
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Comparator;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) {
		InputStream input = System.in;
		OutputStream output = System.out;
		InputReader in = new InputReader(input);
		PrintWriter out = new PrintWriter(output);
		Solve solve = new Solve();
		solve.solve(in, out);
		out.close();
	}

	static class Solve {
		Branch[] br;
		void solve(InputReader in, PrintWriter out) {
			int n = in.nextInt();
			int t = in.nextInt();
			int[] cats = new int[n];
			for(int i = 0; i < n; ++i) {
				cats[i] = in.nextInt();
			}
			br = new Branch[n+1];
			for(int i = 0; i < n-1; ++i) {
				int x = in.nextInt();
				int y = in.nextInt();
				new Branch(x,y);
				new Branch(y,x);
			}
			out.println(Arrays.toString(br));

        }

		void findLeaf() {

		}

		class Branch {
			int to;
			Branch next;
			Branch(int x, int y) {
				this.to = y;
				this.next = br[x];
				br[x] = this;
			}
			public String toString() {
				return to + " " + next;
			}
		}
	}

	static class InputReader {
		BufferedReader br;
		StringTokenizer tokenizer = null;
		InputReader(InputStream in) {
			br = new BufferedReader(new InputStreamReader(in));
		}

		String next() {
			while((tokenizer==null)||(!(tokenizer.hasMoreTokens()))) {
				try {
					tokenizer = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return tokenizer.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) {
		InputStream input = System.in;
		OutputStream output = System.out;
		InputReader in = new InputReader(input);
		PrintWriter out = new PrintWriter(output);
		Solve solve = new Solve();
		solve.solve(in, out);
		out.close();
	}

	static class Solve {
		Branch[] br;
		int result = 0;
		int n = 0;
		int t = 0;
		int[] cats;
		void solve(InputReader in, PrintWriter out) {
			n = in.nextInt();
			t = in.nextInt();
			cats = new int[n + 1];
			for(int i = 1; i <= n; ++i) {
				cats[i] = in.nextInt();
			}
			br = new Branch[n + 1];
			for(int i = 0; i < n-1; ++i) {
				int x = in.nextInt();
				int y = in.nextInt();
				new Branch(x,y);
				new Branch(y,x);
			}
			findLeaf(0, 1, 0);
			out.println(result);

        }

		void findLeaf(int count, int num, int parent) {
			count = cats[num]==1 ? ++count : 0;
			boolean leaf = true;
			if (count > t) {
				return;
			}

			for(Branch b = br[num]; b!=null; b = b.next) {
				if (b.to == parent) {
					continue;
				}
				leaf = false;
				findLeaf(count, b.to, num);
			}

			if (leaf) {
				++result;
			}
		}

		class Branch {
			int to;
			Branch next;
			Branch(int x, int y) {
				this.to = y;
				this.next = br[x];
				br[x] = this;
			}
			public String toString() {
				return to + " " + next;
			}
		}
	}

	static class InputReader {
		BufferedReader br;
		StringTokenizer tokenizer = null;
		InputReader(InputStream in) {
			br = new BufferedReader(new InputStreamReader(in));
		}

		String next() {
			while((tokenizer==null)||(!(tokenizer.hasMoreTokens()))) {
				try {
					tokenizer = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return tokenizer.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}
	}
}


//import java.io.BufferedReader;
//import java.io.IOException;
//import java.io.InputStreamReader;
//
//
//public class Main {
//    public static void main(String[] args) throws IOException {
//        BufferedReader rd = new BufferedReader(new InputStreamReader(System.in));
//        try {
//            int t = Integer.parseInt(rd.readLine());
//            int[] a = new int[t];
//	        if ((t >= 1)&&(t <=100000)) {
//	            String s = rd.readLine();
//	            for(int j = 0; j < t; j++) {
//	            	a[j] = Integer.parseInt(s.split("\\s+")[j]);
//	            	if ((a[j]<1)||(a[j]>1000000000)) {
//	            		throw new IOException();
//	            	}
//	            }
//	            int max = 0;
//	            int k = 1;
//	            for(int i = 1; i < a.length; i++) {
//	            	if (a[i]>=a[i-1]) {
//	            		k++;
//		           		if (k > max) {
//		           			max = k;
//		            	}
//		           	} else {
//		            	k = 1;
//		            }
//	            }
//	            System.out.println(max);
//	        }
//        } catch(Exception e) {
//            System.out.println("Incorrect data type");
//            System.exit(0);
//        }
//    }
//}

//import java.io.BufferedReader;
//import java.io.IOException;
//import java.io.InputStreamReader;
//import java.util.HashSet;
//import java.util.Set;
//
//public class Main {
//    public static void main(String[] args) throws IOException {
//        BufferedReader rd = new BufferedReader(new InputStreamReader(System.in));
//        try {
//        	String [] t = rd.readLine().split("\\s+");
//        	Set<Integer> set = new HashSet<Integer>();
//        	int result = 0;
//        	if (t.length > 2) {
//        		throw new IOException();
//        	}
//        	int a = Integer.parseInt(t[0]);
//        	int b = Integer.parseInt(t[1]);
//        	if ((a<1)||(b<1)||(a>100000)||(b>1000000000)) {
//        		throw new IOException();
//        	}
//        	int[][] all = new int[a][2];
//        	for(int j = 0; j < a; j++) {
//        		String[] temp = rd.readLine().split("\\s+");
//        		if (temp.length > 2) {
//            		throw new IOException();
//            	}
//        		all[j][0] = Integer.parseInt(temp[0]);
//        		all[j][1] = Integer.parseInt(temp[1]);
//        		if ((all[j][0]<0)||(all[j][1]<0)||(all[j][0]>1000000000)||(all[j][1]>1000000000)) {
//            		throw new IOException();
//            	}
//        	}
//            for(int i = 0; i < a; i++) {
//            	int res = 0;
//            	int m = all[i][0];
//            	for(int k = 0; k < a; k++) {
//            		if (Math.abs(all[k][0] - m)<b) {
//            			res += all[k][1];
//            		}
//            	}
//            	if (res > result) {
//            		result = res;
//            	}
//            }
//        	System.out.println(result);
//
//        } catch(Exception e) {
//            System.out.println("Incorrect data type");
//            System.exit(0);
//        }
//    }
//}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class Main {

	static int result = 0;
	static int count = 0;
	static String[] cats;
	static int n;
	static int c;
	static List<Set<Integer[]>> list;

    public static void main(String[] args) throws IOException {
        BufferedReader rd = new BufferedReader(new InputStreamReader(System.in));

        	String [] t = rd.readLine().split("\\s+");
        	n = Integer.parseInt(t[0]);
        	c = Integer.parseInt(t[1]);

        	cats = rd.readLine().split("\\s+");

        	list = new ArrayList<Set<Integer[]>>();
        	int k = 0;
        	for(int i = 0; i < n-1; i++) {
        		String[] str = rd.readLine().split("\\s+");

        		Integer[] a = new Integer[2];
        		a[0] = Integer.parseInt(str[0]);
        		a[1] = Integer.parseInt(str[1]);
        		if (a[0]!=k) {
        			k = a[0];
        			list.add(new HashSet<Integer[]>());
        		}
        		list.get(k-1).add(a);
        	}

        	tree(list.get(0));
        	System.out.println(result);

    }

    public static void tree(Set<Integer[]> set) {
    	for(Integer[] mas : set) {
    		int sor = count;
    		if (Integer.parseInt(cats[mas[1]-1])==1) {
    			count++;
    			if (count<=c){
    				continue;
    			}
    		} else {
    			if (count<=c){
    				result++;
    			}
    		}
    		if (list.size()>mas[1]-1) {
    			tree(list.get(mas[1]-1));
    		}
    		count = sor;
    	}
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

public class Main {

	static int result = 0;
	static int count = 0;
	static String[] cats;
	static int n;
	static int c;

	static Map<Integer, Set<Integer[]>> map;

    public static void main(String[] args) throws IOException {
        BufferedReader rd = new BufferedReader(new InputStreamReader(System.in));

        	String [] t = rd.readLine().split("\\s+");
        	n = Integer.parseInt(t[0]);
        	c = Integer.parseInt(t[1]);

        	cats = rd.readLine().split("\\s+");

        	map = new HashMap<Integer, Set<Integer[]>>();
        	int k = 0;
        	for(int i = 0; i < n-1; i++) {
        		String[] str = rd.readLine().split("\\s+");
        		Integer[] a = new Integer[2];
        		a[0] = Math.min(Integer.parseInt(str[0]), Integer.parseInt(str[1]));
        		a[1] = Math.max(Integer.parseInt(str[0]), Integer.parseInt(str[1]));
        		if (a[0]!=k) {
        			k = a[0];
        			map.put(k, new HashSet<Integer[]>());
        		}
        		map.get(k).add(a);
        	}
        	if (Integer.parseInt(cats[0])==1) {
        		count++;
        	}

        	tree(map.get(1));
        	System.out.println(result);

    }

    public static void tree(Set<Integer[]> set) {
    	for(Integer[] mas : set) {
    		int sor = count;
    		int max = count;
    		if (Integer.parseInt(cats[mas[1]-1])==1) {
    			count++;
    			if (count>max) {
    				max = count;
    			}
    		} else {
    			count = 0;
    		}

    		if (map.containsKey(mas[1])) {
    			tree(map.get(mas[1]));
    		} else {
    			if (max<=c) {
    				result++;
    			}
    		}
    		count = sor;
    	}
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

public class Main {

	static int result = 0;
	static int count = 0;
	static String[] cats;
	static int n;
	static int c;

	static Map<Integer, Set<Integer[]>> map;

    public static void main(String[] args) throws IOException {
        BufferedReader rd = new BufferedReader(new InputStreamReader(System.in));

        	String [] t = rd.readLine().split("\\s+");
        	n = Integer.parseInt(t[0]);
        	c = Integer.parseInt(t[1]);

        	cats = rd.readLine().split("\\s+");

        	map = new HashMap<Integer, Set<Integer[]>>();
        	int k = 0;
        	for(int i = 0; i < n-1; i++) {
        		String[] str = rd.readLine().split("\\s+");

        		Integer[] a = new Integer[2];
        		a[0] = Integer.parseInt(str[0]);
        		a[1] = Integer.parseInt(str[1]);
        		if (a[0]!=k) {
        			k = a[0];

        			map.put(k, new HashSet<Integer[]>());
        		}

        		map.get(k).add(a);
        	}
        	if (Integer.parseInt(cats[0])==1) {
        		count++;
        	}

        	tree(map.get(1));
        	System.out.println(result);

    }

    public static void tree(Set<Integer[]> set) {
    	for(Integer[] mas : set) {
    		int sor = count;
    		if (Integer.parseInt(cats[mas[1]-1])==1) {
    			count++;

    		} else {
    			if (count<=c){
    				result++;
    			}
    		}

    		if (map.containsKey(mas[1])) {
    			tree(map.get(mas[1]));
    		}
    		count = sor;
    	}
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class Main {

	static int result = 0;
	static int count = 0;
	static String[] cats;
	static int n;
	static int c;
	static List<Set<Integer[]>> list;

    public static void main(String[] args) throws IOException {
        BufferedReader rd = new BufferedReader(new InputStreamReader(System.in));

        	String [] t = rd.readLine().split("\\s+");
        	n = Integer.parseInt(t[0]);
        	c = Integer.parseInt(t[1]);

        	cats = rd.readLine().split("\\s+");

        	list = new ArrayList<Set<Integer[]>>();
        	int k = 0;
        	for(int i = 0; i < n-1; i++) {
        		String[] str = rd.readLine().split("\\s+");

        		Integer[] a = new Integer[2];
        		a[0] = Integer.parseInt(str[0]);
        		a[1] = Integer.parseInt(str[1]);
        		if (a[0]!=k) {
        			k = a[0];
        			list.add(new HashSet<Integer[]>());
        		}
        		list.get(k-1).add(a);
        	}

        	tree(list.get(0));
        	System.out.println(result);

    }

    public static void tree(Set<Integer[]> set) {
    	for(Integer[] mas : set) {
    		int sor = count;
    		if (Integer.parseInt(cats[mas[1]-1])==1) {
    			count++;

    		} else {
    			if (count<=c){
    				result++;
    			}
    		}
    		if (list.size()>mas[1]-1) {
    			tree(list.get(mas[1]-1));
    		}
    		count = sor;
    	}
    }
}


/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Ideone
{
    static boolean done[];
    static ArrayList<Integer> sa[];
    static int n;
    static int m;
    static int a[];
    static int cat[];
    static boolean notleaf[];
    public static void main (String[] args) throws java.lang.Exception
    {
        // your code goes here
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        notleaf= new boolean[n];
        m = sc.nextInt();
        a = new int[n];
        for(int i = 0;i<n;i++){
            a[i]=sc.nextInt();
        }
        sa= new ArrayList[n];
        for(int i = 0;i<n;i++){
            sa[i]= new ArrayList<Integer>();
        }
        for(int i = 0;i<n-1;i++){
            sa[sc.nextInt()-1].add(sc.nextInt()-1);
        }
        done = new boolean[n];
        cat = new int[n];
        go(0,-1);
        int ans = 0;
        for(int i = 0;i<n;i++){
            if(!done[i]&&!notleaf[i]){
                ans++;
            }
        }
        System.out.println(ans);
    }
    public static void go(int v, int w){
    //  System.out.println("Before " + v + " and " + w);
        if(w==-1){
            cat[v]=a[v];
            if(cat[v]>m){
                done[v]=true;
            //  System.out.println(v + " is done");
            }
            for(int i : sa[v]){
            //  System.out.print(v + " is " );
                notleaf[v]=true;
            //  System.out.println("ok");
                go(i,v);
            }
        }
        else{
            if(done[w]){
                done[v]=true;
            //  System.out.println(v + " is done");
            }
            if(a[v]==1){
                cat[v]=cat[w]+1;
                if(cat[v]>m){
                    done[v]=true;
                //  System.out.println(v + " is done");
                }
            }
            else{
                cat[v]=0;
            }
            for(int i : sa[v]){
                if(i!=w){
                    notleaf[v]=true;
                    go(i,v);
                }
            }
        }
    }
}


/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Ideone
{
    static boolean done[];
    static ArrayList<Integer> sa[];
    static int n;
    static int m;
    static int a[];
    static int cat[];
    static boolean notleaf[];
    public static void main (String[] args) throws java.lang.Exception
    {
        // your code goes here
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        notleaf= new boolean[n];
        m = sc.nextInt();
        a = new int[n];
        for(int i = 0;i<n;i++){
            a[i]=sc.nextInt();
        }
        sa= new ArrayList[n];
        for(int i = 0;i<n;i++){
            sa[i]= new ArrayList<Integer>();
        }
        for(int i = 0;i<n-1;i++){
            int x = sc.nextInt()-1;
            int y = sc.nextInt()-1;
            sa[x].add(y);
            sa[y].add(x);
        }
        done = new boolean[n];
        cat = new int[n];
        go(0,-1);
        int ans = 0;
        for(int i = 0;i<n;i++){
            if(!done[i]&&!notleaf[i]){
                ans++;
            }
        }
        System.out.println(ans);
    }
    public static void go(int v, int w){
    //  System.out.println("Before " + v + " and " + w);
        if(w==-1){
            cat[v]=a[v];
            if(cat[v]>m){
                done[v]=true;
            //  System.out.println(v + " is done");
            }
            for(int i : sa[v]){
            //  System.out.print(v + " is " );
                notleaf[v]=true;
            //  System.out.println("ok");
                go(i,v);
            }
        }
        else{
            if(done[w]){
                done[v]=true;
            //  System.out.println(v + " is done");
            }
            if(a[v]==1){
                cat[v]=cat[w]+1;
                if(cat[v]>m){
                    done[v]=true;
                //  System.out.println(v + " is done");
                }
            }
            else{
                cat[v]=0;
            }
            for(int i : sa[v]){
                if(i!=w){
                    notleaf[v]=true;
                    go(i,v);
                }
            }
        }
    }
}


import java.util.ArrayList;
import java.util.Scanner;

public class MainC {
	Scanner sc = new Scanner(System.in);

	int n, m, cnt;
	int[] a;
	boolean[] v;
	ArrayList<Integer>[] g;

	@SuppressWarnings("unchecked")
	void run() {
		n = sc.nextInt();
		m = sc.nextInt();
		a = new int[n];
		for (int i = 0; i < n; i++) a[i] = sc.nextInt();
		v = new boolean[n];
		g = new ArrayList[n];
		for (int i = 0; i < n; i++) g[i] = new ArrayList<Integer>();
		for (int i = 0; i < n - 1; i++) {
			int s = sc.nextInt();
			int t = sc.nextInt();
			g[s - 1].add(t - 1);
			g[t - 1].add(s - 1);
		}
		cnt = 0;
		dfs(0, a[0]);
		System.out.println(cnt);
	}

	void dfs(int now, int cat) {
		v[now] = true;
		if (g[now].size() == 1 && now != 0) {
			cnt++;
			return;
		}
		for (Integer next : g[now]) {
			if (!v[next]) {
				if (a[now] == 1 && a[next] + cat <= m) dfs(next, cat + a[next]);
				else if (a[now] == 0) dfs(next, a[next]);
			}
		}
	}

	public static void main(String[] args) {
		new MainC().run();
	}
}


import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class MainC {
	MyScanner sc = new MyScanner();
	Scanner sc2 = new Scanner(System.in);
	long start = System.currentTimeMillis();
	long fin = System.currentTimeMillis();
	final int MOD = 1000000007;
	int[] dx = { 1, 0, 0, -1 };
	int[] dy = { 0, 1, -1, 0 };

	int n, m;
	int[] a;
	int cnt;
	boolean[] v;
	ArrayList<Integer>[] g;

	void run() {
		n = sc.nextInt();
		m = sc.nextInt();
		a = sc.nextIntArray(n);
		v = new boolean[n];
		g = new ArrayList[n];
		for (int i = 0; i < n; i++) g[i] = new ArrayList<Integer>();
		for (int i = 0; i < n - 1; i++) {
			int s = sc.nextInt();
			int t = sc.nextInt();
			g[s - 1].add(t - 1);
			g[t - 1].add(s - 1);
		}
		cnt = 0;
		dfs(0, a[0]);
		System.out.println(cnt);
	}

	void dfs(int now, int cat) {
		v[now] = true;
		if(g[now].size() == 1 && now != 0) {
			cnt ++ ;
			return;
		}
		for (Integer next : g[now]) {
			if (!v[next]) {
				if(a[now] == 1 && a[next] + cat <= m) dfs(next , cat + a[next]);
				else if(a[now] == 0) dfs(next, a[next]);
			}
		}
	}

	public static void main(String[] args) {
		new MainC().run();
	}

	void debug(Object... o) {
		System.out.println(Arrays.deepToString(o));
	}

	void debug2(int[][] array) {
		for (int i = 0; i < array.length; i++) {
			for (int j = 0; j < array[i].length; j++) {
				System.out.print(array[i][j]);
			}
			System.out.println();
		}
	}

	boolean inner(int h, int w, int limH, int limW) {
		return 0 <= h && h < limH && 0 <= w && w < limW;
	}

	void swap(int[] x, int a, int b) {
		int tmp = x[a];
		x[a] = x[b];
		x[b] = tmp;
	}

	// find minimum i (a[i] >= border)
	int lower_bound(int a[], int border) {
		int l = -1;
		int r = a.length;
		while (r - l > 1) {
			int mid = (l + r) / 2;
			if (border <= a[mid]) {
				r = mid;
			} else {
				l = mid;
			}
		}
		// r = l + 1
		return r;
	}

	boolean palindrome(String s) {
		for (int i = 0; i < s.length() / 2; i++) {
			if (s.charAt(i) != s.charAt(s.length() - 1 - i)) {
				return false;
			}
		}
		return true;
	}

	class MyScanner {
		int nextInt() {
			try {
				int c = System.in.read();
				while (c != '-' && (c < '0' || '9' < c))
					c = System.in.read();
				if (c == '-')
					return -nextInt();
				int res = 0;
				do {
					res *= 10;
					res += c - '0';
					c = System.in.read();
				} while ('0' <= c && c <= '9');
				return res;
			} catch (Exception e) {
				return -1;
			}
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		String next() {
			try {
				StringBuilder res = new StringBuilder("");
				int c = System.in.read();
				while (Character.isWhitespace(c))
					c = System.in.read();
				do {
					res.append((char) c);
				} while (!Character.isWhitespace(c = System.in.read()));
				return res.toString();
			} catch (Exception e) {
				return null;
			}
		}

		int[] nextIntArray(int n) {
			int[] in = new int[n];
			for (int i = 0; i < n; i++) {
				in[i] = nextInt();
			}
			return in;
		}

		int[][] nextInt2dArray(int n, int m) {
			int[][] in = new int[n][m];
			for (int i = 0; i < n; i++) {
				in[i] = nextIntArray(m);
			}
			return in;
		}

		double[] nextDoubleArray(int n) {
			double[] in = new double[n];
			for (int i = 0; i < n; i++) {
				in[i] = nextDouble();
			}
			return in;
		}

		long[] nextLongArray(int n) {
			long[] in = new long[n];
			for (int i = 0; i < n; i++) {
				in[i] = nextLong();
			}
			return in;
		}

		char[][] nextCharField(int n, int m) {
			char[][] in = new char[n][m];
			for (int i = 0; i < n; i++) {
				String s = sc.next();
				for (int j = 0; j < m; j++) {
					in[i][j] = s.charAt(j);
				}
			}
			return in;
		}
	}
}


import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.InputMismatchException;
import java.util.LinkedList;

public class KefaAndParks {
	private static final InputReader in = new InputReader(System.in);
	private Node[] tree;

	public void solve() throws IOException {
		int n = in.readInt();
		int m = in.readInt();
		tree = new Node[n + 1];

		for (int i = 1; i <= n; i++) {
			tree[i] = new Node(i, in.readInt());
		}
		for (int i = 0; i < n - 1; i++) {
			int x = in.readInt();
			int y = in.readInt();
			tree[x].neighs.add(y);
			tree[y].neighs.add(x);
		}
		int result = 0;
		LinkedList<Integer> q = new LinkedList<Integer>();
		q.add(1);

		while (!q.isEmpty()) {
			Node curr = tree[q.pollLast()];
			curr.visited = true;
			System.out.println(curr.index + " cats: " + curr.cats);

			for (int j : curr.neighs) {
				Node child = tree[j];
				if (child.visited) continue;
				if (child.cats > 0) child.cats += curr.cats;
			}

			for (int j : curr.neighs) {
				Node child = tree[j];

				if (child.visited) continue;
				if (child.cats > m) continue;
				if (child.isLeaf()) result++;
				q.add(child.index);
			}
		}
		System.out.println(result);
	}

	class Node {
		int index;
		int cats;
		boolean visited;
		ArrayList<Integer> neighs = new ArrayList<Integer>();

		public Node(int i, int c) {
			this.visited = false;
			this.index = i;
			this.cats = c;
			this.neighs = new ArrayList<Integer>();
		}

		public boolean isLeaf() {
			return neighs.size() == 1;
		}
	}

	public static void main(String[] args) throws IOException {
		new KefaAndParks().solve();
	}

	@SuppressWarnings("unused")
	private static class InputReader {
		private InputStream stream;
		private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;
		private SpaceCharFilter filter;

		public InputReader(InputStream stream) {
			this.stream = stream;
		}

		public int read() {
			if (numChars == -1)
				throw new InputMismatchException();
			if (curChar >= numChars) {
				curChar = 0;
				try {
					numChars = stream.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (numChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		public void readIntArray(int[] a) {
			for (int i = 0; i < a.length; i++) {
				a[i] = this.readInt();
			}
		}

		public int readInt() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public boolean isSpaceChar(int c) {
			if (filter != null)
				return filter.isSpaceChar(c);
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		public interface SpaceCharFilter {
			public boolean isSpaceChar(int ch);
		}
	}
}


import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.InputMismatchException;
import java.util.LinkedList;

public class KefaAndParks {
	private static final InputReader in = new InputReader(System.in);
	private Node[] tree;

	public void solve() throws IOException {
		int n = in.readInt();
		int m = in.readInt();
		tree = new Node[n + 1];

		for (int i = 1; i <= n; i++) {
			tree[i] = new Node(i, in.readInt());
		}
		for (int i = 0; i < n - 1; i++) {
			int x = in.readInt();
			int y = in.readInt();
			tree[x].neighs.add(y);
			tree[y].neighs.add(x);
		}
		int result = 0;
		LinkedList<Integer> q = new LinkedList<Integer>();
		q.add(1);

		while (!q.isEmpty()) {
			Node curr = tree[q.pollLast()];
			curr.visited = true;
			//System.out.println(curr.index + " cats: " + curr.cats);

			for (int j : curr.neighs) {
				Node child = tree[j];
				if (child.visited) continue;
				if (child.cats > 0) child.cats += curr.cats;
			}

			for (int j : curr.neighs) {
				Node child = tree[j];

				if (child.visited) continue;
				if (child.cats > m) continue;
				if (child.isLeaf()) result++;
				q.add(child.index);
			}
		}
		System.out.println(result);
	}

	class Node {
		int index;
		int cats;
		boolean visited;
		ArrayList<Integer> neighs = new ArrayList<Integer>();

		public Node(int i, int c) {
			this.visited = false;
			this.index = i;
			this.cats = c;
			this.neighs = new ArrayList<Integer>();
		}

		public boolean isLeaf() {
			return neighs.size() == 1;
		}
	}

	public static void main(String[] args) throws IOException {
		new KefaAndParks().solve();
	}

	@SuppressWarnings("unused")
	private static class InputReader {
		private InputStream stream;
		private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;
		private SpaceCharFilter filter;

		public InputReader(InputStream stream) {
			this.stream = stream;
		}

		public int read() {
			if (numChars == -1)
				throw new InputMismatchException();
			if (curChar >= numChars) {
				curChar = 0;
				try {
					numChars = stream.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (numChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		public void readIntArray(int[] a) {
			for (int i = 0; i < a.length; i++) {
				a[i] = this.readInt();
			}
		}

		public int readInt() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public boolean isSpaceChar(int c) {
			if (filter != null)
				return filter.isSpaceChar(c);
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		public interface SpaceCharFilter {
			public boolean isSpaceChar(int ch);
		}
	}
}


import java.util.*;
import java.io.*;

public class CF580C{

	private static InputStream stream;
	private static byte[] buf = new byte[1024];
	private static int curChar;
	private static int numChars;
	private static SpaceCharFilter filter;
	private static PrintWriter pw;

	private static class Node{
		ArrayList<Integer> child;
		boolean cat;
		int cons;

		Node(int a){
			child = new ArrayList<Integer>();
			if(a==1) cat = true;
			else cat = false;
			cons = 0;
		}
	}

	private static void inorder1(int a,int prev, int par){
		if(tree[a].cat == true)
			tree[a].cons = prev + 1;
		else
			tree[a].cons = 0;

		if(tree[a].cons > l)
			return;

		for (int i : tree[a].child) {
			if(i!=par)
				inorder1(i,tree[a].cons,a);
		}

		if(tree[a].child.size() == 1 && a!=0)
			count++;

	}

	static int l;
	static int count;
	static Node[] tree;

	private static void soln(){
		int n = nextInt();
		l = nextInt();
		count = 0;
		tree = new Node[n];
		for (int i=0; i<n; i++) {
			tree[i] = new Node(nextInt());
		}

		for (int i=1; i<n; i++) {
			int a = nextInt();a--;
			int b = nextInt();b--;
			tree[a].child.add(b);
			tree[b].child.add(a);
		}

		inorder1(0,0,-1);

		pw.println(count);
	}

	public static void main(String[] args){
		InputReader(System.in);
		pw = new PrintWriter(System.out);
		soln();
		pw.close();
	}

	// To Get Input
	// Some Buffer Methods

	public static void InputReader(InputStream stream1) {
		stream = stream1;
	}

	private static boolean isWhitespace(int c) {
		return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
	}

	private static boolean isEndOfLine(int c) {
		return c == '\n' || c == '\r' || c == -1;
	}

	private static int read() {
		if (numChars == -1)
			throw new InputMismatchException();
		if (curChar >= numChars) {
			curChar = 0;
			try {
				numChars = stream.read(buf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (numChars <= 0)
				return -1;
		}
		return buf[curChar++];
	}

	private static int nextInt() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		int res = 0;
		do {
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

	private static long nextLong() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		long res = 0;
		do {
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

	private static String nextToken() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		StringBuilder res = new StringBuilder();
		do {
			res.appendCodePoint(c);
			c = read();
		} while (!isSpaceChar(c));
		return res.toString();
	}

	private static String nextLine() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		StringBuilder res = new StringBuilder();
		do {
			res.appendCodePoint(c);
			c = read();
		} while (!isEndOfLine(c));
		return res.toString();
	}

	private static int[] nextIntArray(int n) {
		int[] arr = new int[n];
		for (int i = 0; i < n; i++) {
			arr[i] = nextInt();
		}
		return arr;
	}

	private static long[] nextLongArray(int n) {
		long[] arr = new long[n];
		for (int i = 0; i < n; i++) {
			arr[i] = nextLong();
		}
		return arr;
	}

	private static void pArray(int[] arr){
		for (int i=0; i<arr.length; i++) {
			System.out.print(arr[i] + " ");
		}
		System.out.println();
		return;
	}

	private static void pArray(long[] arr){
		for (int i=0; i<arr.length; i++) {
			System.out.print(arr[i] + " ");
		}
		System.out.println();
		return;
	}

	private static boolean isSpaceChar(int c) {
		if (filter != null)
			return filter.isSpaceChar(c);
		return isWhitespace(c);
	}

	private interface SpaceCharFilter {
		public boolean isSpaceChar(int ch);
	}

}


import java.util.*;
import java.io.*;

public class CF580C{

	private static InputStream stream;
	private static byte[] buf = new byte[1024];
	private static int curChar;
	private static int numChars;
	private static SpaceCharFilter filter;
	private static PrintWriter pw;

	private static class Node{
		int parent;
		ArrayList<Integer> child;
		boolean cat;
		int cons;

		Node(int a){
			parent = -1;
			child = new ArrayList<Integer>();
			if(a==1) cat = true;
			else cat = false;
			cons = 0;
		}
	}

	private static void inorder1(int a){
		if(a == 0){
			if(tree[a].cat == true)
				tree[a].cons = 1;
			else
				tree[a].cons = 0;
		}
		else{
			if(tree[a].cat == true)
				tree[a].cons = tree[tree[a].parent].cons + 1;
			else
				tree[a].cons = 0;
		}

		for (int i : tree[a].child) {
			inorder1(i);
		}

	}

	private static void inorder2(int a){
		if(tree[a].cons > l)
			return;
		for (int i : tree[a].child) {
			inorder2(i);
		}

		if(tree[a].child.size() == 0)
			count++;

	}
	static int l;
	static int count;
	static Node[] tree;

	private static void soln(){
		int n = nextInt();
		l = nextInt();
		count = 0;
		tree = new Node[n];
		for (int i=0; i<n; i++) {
			tree[i] = new Node(nextInt());
		}

		for (int i=1; i<n; i++) {
			int a = nextInt();
			int b = nextInt();
			tree[a-1].child.add(b-1);
			tree[b-1].parent=a-1;
		}

		inorder1(0);
		inorder2(0);

		pw.println(count);
	}

	public static void main(String[] args){
		InputReader(System.in);
		pw = new PrintWriter(System.out);
		soln();
		pw.close();
	}

	// To Get Input
	// Some Buffer Methods

	public static void InputReader(InputStream stream1) {
		stream = stream1;
	}

	private static boolean isWhitespace(int c) {
		return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
	}

	private static boolean isEndOfLine(int c) {
		return c == '\n' || c == '\r' || c == -1;
	}

	private static int read() {
		if (numChars == -1)
			throw new InputMismatchException();
		if (curChar >= numChars) {
			curChar = 0;
			try {
				numChars = stream.read(buf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (numChars <= 0)
				return -1;
		}
		return buf[curChar++];
	}

	private static int nextInt() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		int res = 0;
		do {
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

	private static long nextLong() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		long res = 0;
		do {
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

	private static String nextToken() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		StringBuilder res = new StringBuilder();
		do {
			res.appendCodePoint(c);
			c = read();
		} while (!isSpaceChar(c));
		return res.toString();
	}

	private static String nextLine() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		StringBuilder res = new StringBuilder();
		do {
			res.appendCodePoint(c);
			c = read();
		} while (!isEndOfLine(c));
		return res.toString();
	}

	private static int[] nextIntArray(int n) {
		int[] arr = new int[n];
		for (int i = 0; i < n; i++) {
			arr[i] = nextInt();
		}
		return arr;
	}

	private static long[] nextLongArray(int n) {
		long[] arr = new long[n];
		for (int i = 0; i < n; i++) {
			arr[i] = nextLong();
		}
		return arr;
	}

	private static void pArray(int[] arr){
		for (int i=0; i<arr.length; i++) {
			System.out.print(arr[i] + " ");
		}
		System.out.println();
		return;
	}

	private static void pArray(long[] arr){
		for (int i=0; i<arr.length; i++) {
			System.out.print(arr[i] + " ");
		}
		System.out.println();
		return;
	}

	private static boolean isSpaceChar(int c) {
		if (filter != null)
			return filter.isSpaceChar(c);
		return isWhitespace(c);
	}

	private interface SpaceCharFilter {
		public boolean isSpaceChar(int ch);
	}

}


import java.util.*;
import java.io.*;

public class CF580C{

	private static InputStream stream;
	private static byte[] buf = new byte[1024];
	private static int curChar;
	private static int numChars;
	private static SpaceCharFilter filter;
	private static PrintWriter pw;

	private static class Node{
		int parent;
		ArrayList<Integer> child;
		boolean cat;
		int cons;

		Node(int a){
			parent = -1;
			child = new ArrayList<Integer>();
			if(a==1) cat = true;
			else cat = false;
			cons = 0;
		}
	}

	private static void inorder1(int a){
		if(a == 0){
			if(tree[a].cat == true)
				tree[a].cons = 1;
			else
				tree[a].cons = 0;
		}
		else{
			if(tree[a].cat == true)
				tree[a].cons = tree[tree[a].parent].cons + 1;
			else
				tree[a].cons = 0;
		}

		for (int i : tree[a].child) {
			inorder1(i);
		}

	}

	private static void inorder2(int a){
		if(tree[a].cons > l)
			return;
		for (int i : tree[a].child) {
			inorder2(i);
		}

		if(tree[a].child.size() == 0)
			count++;

	}
	static int l;
	static int count;
	static Node[] tree;

	private static void soln(){
		int n = nextInt();
		l = nextInt();
		count = 0;
		tree = new Node[n];
		for (int i=0; i<n; i++) {
			tree[i] = new Node(nextInt());
		}

		for (int i=1; i<n; i++) {
			int a = nextInt();a--;
			int b = nextInt();b--;
			tree[Math.min(a,b)].child.add(Math.max(a,b));
			tree[Math.max(a,b)].parent=Math.min(a,b);
		}

		inorder1(0);
		inorder2(0);

		pw.println(count);
	}

	public static void main(String[] args){
		InputReader(System.in);
		pw = new PrintWriter(System.out);
		soln();
		pw.close();
	}

	// To Get Input
	// Some Buffer Methods

	public static void InputReader(InputStream stream1) {
		stream = stream1;
	}

	private static boolean isWhitespace(int c) {
		return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
	}

	private static boolean isEndOfLine(int c) {
		return c == '\n' || c == '\r' || c == -1;
	}

	private static int read() {
		if (numChars == -1)
			throw new InputMismatchException();
		if (curChar >= numChars) {
			curChar = 0;
			try {
				numChars = stream.read(buf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (numChars <= 0)
				return -1;
		}
		return buf[curChar++];
	}

	private static int nextInt() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		int res = 0;
		do {
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

	private static long nextLong() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		long res = 0;
		do {
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

	private static String nextToken() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		StringBuilder res = new StringBuilder();
		do {
			res.appendCodePoint(c);
			c = read();
		} while (!isSpaceChar(c));
		return res.toString();
	}

	private static String nextLine() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		StringBuilder res = new StringBuilder();
		do {
			res.appendCodePoint(c);
			c = read();
		} while (!isEndOfLine(c));
		return res.toString();
	}

	private static int[] nextIntArray(int n) {
		int[] arr = new int[n];
		for (int i = 0; i < n; i++) {
			arr[i] = nextInt();
		}
		return arr;
	}

	private static long[] nextLongArray(int n) {
		long[] arr = new long[n];
		for (int i = 0; i < n; i++) {
			arr[i] = nextLong();
		}
		return arr;
	}

	private static void pArray(int[] arr){
		for (int i=0; i<arr.length; i++) {
			System.out.print(arr[i] + " ");
		}
		System.out.println();
		return;
	}

	private static void pArray(long[] arr){
		for (int i=0; i<arr.length; i++) {
			System.out.print(arr[i] + " ");
		}
		System.out.println();
		return;
	}

	private static boolean isSpaceChar(int c) {
		if (filter != null)
			return filter.isSpaceChar(c);
		return isWhitespace(c);
	}

	private interface SpaceCharFilter {
		public boolean isSpaceChar(int ch);
	}

}


import java.util.*;
import java.io.*;
import java.math.*;
import java.text.*;
@SuppressWarnings("unchecked")
public class Main
{
  static FastScanner in = new FastScanner(System.in);
  static StringBuilder sb = new StringBuilder();
  static DecimalFormat df = new DecimalFormat();
  static int N;
  static int M;
  static ArrayList<Integer> adj[];
  static boolean cat[];
  public static void main(String[] args)
  {
    df.setMaximumFractionDigits(20);
    df.setMinimumFractionDigits(20);
    df.setRoundingMode(RoundingMode.DOWN);
    // String formatted = df.format(0.2);
    // Never sort array of primitive type
    N = in.nextInt();
    M = in.nextInt();
    cat = new boolean[N];
    adj = new ArrayList[N];
    for (int i = 0; i < N; i++)
      cat[i] = in.nextInt() == 1;
    for (int i = 0; i < N; i++)
      adj[i] = new ArrayList<Integer>();
    for (int i = 0; i < N - 1; i++)
    {
      int x = in.nextInt() - 1;
      int y = in.nextInt() - 1;
      adj[x].add(y);
      adj[y].add(x);
    }
    int ans = dfs(0, -1, 0);
    sb.append(ans);
    sb.append('\n');
    System.out.print(sb.toString());
  }
  static int dfs(int u, int p, int cnt)
  {
    if (!cat[u])
    {
      cnt = 0;
    }
    else
    {
      cnt ++;
    }
    if (cnt > M)
    {
      return 0;
    }
    int ans = 0;
    if (adj[u].size() == 1)
    {
      // leaf
//      System.out.println("leaf = " + u);
      return 1;
    }
    for (Integer v : adj[u])
    {
      if (v == p) continue;
      ans += dfs(v, u, cnt);
    }
    return ans;
  }
  static BigInteger b(long n) { return BigInteger.valueOf(n);}
  static BigInteger b(String s) { return new BigInteger(s); }
  static BigDecimal bd(double d) { return BigDecimal.valueOf(d);}
  static BigDecimal bd(String s) { return new BigDecimal(s); }
}
class FastScanner
{
  BufferedReader reader;
  StringTokenizer tokenizer;
  FastScanner (InputStream inputStream)
  {
    reader = new BufferedReader(new InputStreamReader(inputStream));
  }
  String nextToken()
  {
    while (tokenizer == null || ! tokenizer.hasMoreTokens())
    {
      try {
        tokenizer = new StringTokenizer(reader.readLine());
      } catch (Exception e){}
    }
    return tokenizer.nextToken();
  }
  boolean hasNext()
  {
    if (tokenizer == null || ! tokenizer.hasMoreTokens())
    {
      try {
        tokenizer = new StringTokenizer(reader.readLine());
      } catch (Exception e){ return false; }
    }
    return true;
  }
  int nextInt()
  {
    return Integer.parseInt(nextToken());
  }
}


import java.util.*;
import java.io.*;
import java.math.*;
import java.text.*;
@SuppressWarnings("unchecked")
public class Main
{
  static FastScanner in = new FastScanner(System.in);
  static StringBuilder sb = new StringBuilder();
  static DecimalFormat df = new DecimalFormat();
  static int N;
  static int M;
  static ArrayList<Integer> adj[];
  static boolean cat[];
  public static void main(String[] args)
  {
    df.setMaximumFractionDigits(20);
    df.setMinimumFractionDigits(20);
    df.setRoundingMode(RoundingMode.DOWN);
    // String formatted = df.format(0.2);
    // Never sort array of primitive type
    N = in.nextInt();
    M = in.nextInt();
    cat = new boolean[N];
    adj = new ArrayList[N];
    for (int i = 0; i < N; i++)
      cat[i] = in.nextInt() == 1;
    for (int i = 0; i < N; i++)
      adj[i] = new ArrayList<Integer>();
    for (int i = 0; i < N - 1; i++)
    {
      int x = in.nextInt() - 1;
      int y = in.nextInt() - 1;
      adj[x].add(y);
      adj[y].add(x);
    }
    int ans = dfs(0, -1, 0);
    sb.append(ans);
    sb.append('\n');
    System.out.print(sb.toString());
  }
  static int dfs(int u, int p, int cnt)
  {
    if (cnt > M)
    {
      return 0;
    }
    if (!cat[u])
    {
      cnt = 0;
    }
    else
    {
      cnt ++;
    }
    if (cnt > M)
    {
      return 0;
    }
    int ans = 0;
    if (adj[u].size() == 1)
    {
      // leaf
//      System.out.println("leaf = " + u);
      return 1;
    }
    for (Integer v : adj[u])
    {
      if (v == p) continue;
      ans += dfs(v, u, cnt);
    }
    return ans;
  }
  static BigInteger b(long n) { return BigInteger.valueOf(n);}
  static BigInteger b(String s) { return new BigInteger(s); }
  static BigDecimal bd(double d) { return BigDecimal.valueOf(d);}
  static BigDecimal bd(String s) { return new BigDecimal(s); }
}
class FastScanner
{
  BufferedReader reader;
  StringTokenizer tokenizer;
  FastScanner (InputStream inputStream)
  {
    reader = new BufferedReader(new InputStreamReader(inputStream));
  }
  String nextToken()
  {
    while (tokenizer == null || ! tokenizer.hasMoreTokens())
    {
      try {
        tokenizer = new StringTokenizer(reader.readLine());
      } catch (Exception e){}
    }
    return tokenizer.nextToken();
  }
  boolean hasNext()
  {
    if (tokenizer == null || ! tokenizer.hasMoreTokens())
    {
      try {
        tokenizer = new StringTokenizer(reader.readLine());
      } catch (Exception e){ return false; }
    }
    return true;
  }
  int nextInt()
  {
    return Integer.parseInt(nextToken());
  }
}


import java.util.*;
import java.io.*;
import java.math.*;
import java.text.*;
@SuppressWarnings("unchecked")
public class Main
{
  static FastScanner in = new FastScanner(System.in);
  static StringBuilder sb = new StringBuilder();
  static DecimalFormat df = new DecimalFormat();
  static int N;
  static int M;
  static ArrayList<Integer> adj[];
  static boolean cat[];
  public static void main(String[] args)
  {
    df.setMaximumFractionDigits(20);
    df.setMinimumFractionDigits(20);
    df.setRoundingMode(RoundingMode.DOWN);
    // String formatted = df.format(0.2);
    // Never sort array of primitive type
    N = in.nextInt();
    M = in.nextInt();
    cat = new boolean[N];
    adj = new ArrayList[N];
    for (int i = 0; i < N; i++)
      cat[i] = in.nextInt() == 1;
    for (int i = 0; i < N; i++)
      adj[i] = new ArrayList<Integer>();
    for (int i = 0; i < N - 1; i++)
    {
      int x = in.nextInt() - 1;
      int y = in.nextInt() - 1;
      adj[x].add(y);
      adj[y].add(x);
    }
    int ans = dfs(0, -1, 0);
    sb.append(ans);
    sb.append('\n');
    System.out.print(sb.toString());
  }
  static int dfs(int u, int p, int cnt)
  {
    if (!cat[u])
    {
      cnt = 0;
    }
    else
    {
      cnt ++;
    }
    if (cnt > M)
    {
      return 0;
    }
    int ans = 0;
    if (adj[u].size() == 1)
    {
      // leaf
//      System.out.println("leaf = " + u);
if (u > 0) ans = 1;
    }
    for (Integer v : adj[u])
    {
      if (v == p) continue;
      ans += dfs(v, u, cnt);
    }
    return ans;
  }
  static BigInteger b(long n) { return BigInteger.valueOf(n);}
  static BigInteger b(String s) { return new BigInteger(s); }
  static BigDecimal bd(double d) { return BigDecimal.valueOf(d);}
  static BigDecimal bd(String s) { return new BigDecimal(s); }
}
class FastScanner
{
  BufferedReader reader;
  StringTokenizer tokenizer;
  FastScanner (InputStream inputStream)
  {
    reader = new BufferedReader(new InputStreamReader(inputStream));
  }
  String nextToken()
  {
    while (tokenizer == null || ! tokenizer.hasMoreTokens())
    {
      try {
        tokenizer = new StringTokenizer(reader.readLine());
      } catch (Exception e){}
    }
    return tokenizer.nextToken();
  }
  boolean hasNext()
  {
    if (tokenizer == null || ! tokenizer.hasMoreTokens())
    {
      try {
        tokenizer = new StringTokenizer(reader.readLine());
      } catch (Exception e){ return false; }
    }
    return true;
  }
  int nextInt()
  {
    return Integer.parseInt(nextToken());
  }
}


import java.util.*;
import java.io.*;
import java.math.*;
import java.text.*;
@SuppressWarnings("unchecked")
public class Main
{
  static FastScanner in = new FastScanner(System.in);
  static StringBuilder sb = new StringBuilder();
  static DecimalFormat df = new DecimalFormat();
  static int N;
  static int M;
  static ArrayList<Integer> adj[];
  static boolean cat[];
  public static void main(String[] args)
  {
    df.setMaximumFractionDigits(20);
    df.setMinimumFractionDigits(20);
    df.setRoundingMode(RoundingMode.DOWN);
    // String formatted = df.format(0.2);
    // Never sort array of primitive type
    N = in.nextInt();
    M = in.nextInt();
    cat = new boolean[N];
    adj = new ArrayList[N];
    for (int i = 0; i < N; i++)
      cat[i] = in.nextInt() == 1;
    for (int i = 0; i < N; i++)
      adj[i] = new ArrayList<Integer>();
    for (int i = 0; i < N - 1; i++)
    {
      int x = in.nextInt() - 1;
      int y = in.nextInt() - 1;
      adj[x].add(y);
      adj[y].add(x);
    }
    int ans = dfs(0, -1, 0);
    sb.append(ans);
    sb.append('\n');
    System.out.print(sb.toString());
  }
  static int dfs(int u, int p, int cnt)
  {
    if (!cat[u])
    {
      cnt = 0;
    }
    else
    {
      cnt ++;
    }
    if (cnt > M)
    {
      return 0;
    }
    int ans = 0;
    if (adj[u].size() == 1)
    {
      // leaf
//      System.out.println("leaf = " + u);
      ans = 1;
    }
    for (Integer v : adj[u])
    {
      if (v == p) continue;
      ans += dfs(v, u, cnt);
    }
    return ans;
  }
  static BigInteger b(long n) { return BigInteger.valueOf(n);}
  static BigInteger b(String s) { return new BigInteger(s); }
  static BigDecimal bd(double d) { return BigDecimal.valueOf(d);}
  static BigDecimal bd(String s) { return new BigDecimal(s); }
}
class FastScanner
{
  BufferedReader reader;
  StringTokenizer tokenizer;
  FastScanner (InputStream inputStream)
  {
    reader = new BufferedReader(new InputStreamReader(inputStream));
  }
  String nextToken()
  {
    while (tokenizer == null || ! tokenizer.hasMoreTokens())
    {
      try {
        tokenizer = new StringTokenizer(reader.readLine());
      } catch (Exception e){}
    }
    return tokenizer.nextToken();
  }
  boolean hasNext()
  {
    if (tokenizer == null || ! tokenizer.hasMoreTokens())
    {
      try {
        tokenizer = new StringTokenizer(reader.readLine());
      } catch (Exception e){ return false; }
    }
    return true;
  }
  int nextInt()
  {
    return Integer.parseInt(nextToken());
  }
}


import java.io.*;
import java.util.*;

public class Solution
{
    public static void main(String args[] ) throws Exception
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        String[] sapera=br.readLine().split(" ");
        int n=Integer.parseInt(sapera[0]);
        int m=Integer.parseInt(sapera[1]);
        Solution s=new Solution();
        s.caaal(n,m,br);
        br.close();
    }

    private void caaal(int n, int m, BufferedReader br) throws IOException {
        // TODO Auto-generated method stub
        String[] vert=br.readLine().split(" ");
        BinaryTree[] b=new BinaryTree[n+1];
        b[0]=new BinaryTree();
        boolean[] ba=new boolean[n+1];
        for(int i=1;i<=n;i++)
        {
            b[i]=new BinaryTree();
            b[i].cat=Integer.parseInt(vert[i-1]);
            b[i].vert=i;
        }

        for(int i=0;i<n-1;i++)
        {
             String[] s=br.readLine().split(" ");
             b[Integer.parseInt(s[0])].ar.add(b[Integer.parseInt(s[1])]);
             b[Integer.parseInt(s[1])].ar.add(b[Integer.parseInt(s[0])]);
        }

        int count=0;
        int temp;
        int bbb=(b[1].cat==0?0:1);
        ba[1]=true;
        for(BinaryTree bb: b[1].ar)
        {
            //System.out.println(bb.vert);
            if(ba[bb.vert])
                continue;
            ba[bb.vert]=true;
            temp=recur(bb,bbb,m,ba);
            count+=temp;
        }
        System.out.println(count);
    }

    private int recur(BinaryTree bb, int i,int m,boolean[] ba) {
        // TODO Auto-generated method stub

        if(i>m)
            return 0;

        if(bb.cat==1)
            i++;
        else
            i=0;

        if(!bb.ar.isEmpty())
        {
                int temp,count=0;
                for(BinaryTree bbb: bb.ar)
                {
                    if(ba[bbb.vert])
                        continue;
                    temp=recur(bbb,i,m,ba);
                    count+=temp;
                }
                return count;
        }

        else
        {if(i>m) return 0;}
        //System.out.println(bb.vert);
        return 1;

    }

    public class BinaryTree
    {
        int cat;
        int vert;
        ArrayList<BinaryTree> ar=new ArrayList<BinaryTree>();
    }
}


import java.io.*;
import java.util.*;

public class Solution
{
    public static void main(String args[] ) throws Exception
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        String[] sapera=br.readLine().split(" ");
        int n=Integer.parseInt(sapera[0]);
        int m=Integer.parseInt(sapera[1]);
        Solution s=new Solution();
        s.caaal(n,m,br);
        br.close();
    }

    private void caaal(int n, int m, BufferedReader br) throws IOException {
        // TODO Auto-generated method stub
        String[] vert=br.readLine().split(" ");
        BinaryTree[] b=new BinaryTree[n+1];
        b[0]=new BinaryTree();
        boolean[] ba=new boolean[n+1];
        for(int i=1;i<=n;i++)
        {
            b[i]=new BinaryTree();
            b[i].cat=Integer.parseInt(vert[i-1]);
            b[i].vert=i;
        }

        for(int i=0;i<n-1;i++)
        {
             String[] s=br.readLine().split(" ");
             b[Integer.parseInt(s[0])].ar.add(b[Integer.parseInt(s[1])]);
             b[Integer.parseInt(s[1])].ar.add(b[Integer.parseInt(s[0])]);
        }

        int count=0;
        int temp;
        int bbb=(b[1].cat==0?0:1);
        ba[1]=true;
        for(BinaryTree bb: b[1].ar)
        {
            //System.out.println(bb.vert);
            if(ba[bb.vert])
                continue;
            ba[bb.vert]=true;
            temp=recur(bb,bbb,m,ba);
            count+=temp;
        }
        System.out.println(count);
    }

    private int recur(BinaryTree bb, int i,int m,boolean[] ba) {
        // TODO Auto-generated method stub

        if(i>m)
            return 0;

        if(bb.cat==1)
            i++;
        else
            i=0;
        int temp,count=0;
        boolean flag=false;
        for(BinaryTree bbb: bb.ar)
        {
            if(ba[bbb.vert])
                continue;
            flag=true;
            ba[bbb.vert]=true;
            temp=recur(bbb,i,m,ba);
            count+=temp;
            }
        if(flag)
        return count;

        if(i>m) return 0;

        return 1;

    }

    public class BinaryTree
    {
        int cat;
        int vert;
        ArrayList<BinaryTree> ar=new ArrayList<BinaryTree>();
    }
}


import java.io.*;
import java.util.*;

public class Solution
{
    public static void main(String args[] ) throws Exception
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        String[] sapera=br.readLine().split(" ");
        int n=Integer.parseInt(sapera[0]);
        int m=Integer.parseInt(sapera[1]);
        Solution s=new Solution();
        s.caaal(n,m,br);
        br.close();
    }

    private void caaal(int n, int m, BufferedReader br) throws IOException {
        // TODO Auto-generated method stub
        String[] vert=br.readLine().split(" ");
        BinaryTree[] b=new BinaryTree[n+1];
        b[0]=new BinaryTree();
        boolean[] ba=new boolean[n+1];
        for(int i=1;i<=n;i++)
        {
            b[i]=new BinaryTree();
            b[i].cat=Integer.parseInt(vert[i-1]);
            b[i].vert=i;
        }

        for(int i=0;i<n-1;i++)
        {
             String[] s=br.readLine().split(" ");
             b[Integer.parseInt(s[0])].ar.add(b[Integer.parseInt(s[1])]);
             b[Integer.parseInt(s[1])].ar.add(b[Integer.parseInt(s[0])]);
        }

        int count=0;
        int temp;
        int bbb=(b[1].cat==0?0:1);
        ba[1]=true;
        for(BinaryTree bb: b[1].ar)
        {
            //System.out.println(bb.vert);
            if(ba[bb.vert])
                continue;
            ba[bb.vert]=true;
            temp=recur(bb,bbb,m,ba);
            count+=temp;
        }
        System.out.println(count);
    }

    private int recur(BinaryTree bb, int i,int m,boolean[] ba) {
        // TODO Auto-generated method stub

        if(i>m)
            return 0;

        if(bb.cat==1)
            i++;
        else
            i=0;
        int temp,count=0;
        boolean flag=false;
        for(BinaryTree bbb: bb.ar)
        {
            if(ba[bbb.vert])
                continue;
            flag=true;
            temp=recur(bbb,i,m,ba);
            count+=temp;
            }
        if(flag)
        return count;

        if(i>m) return 0;

        return 1;

    }

    public class BinaryTree
    {
        int cat;
        int vert;
        ArrayList<BinaryTree> ar=new ArrayList<BinaryTree>();
    }
}


import java.io.*;
import java.util.*;

public class Solution
{
    public static void main(String args[] ) throws Exception
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        String[] sapera=br.readLine().split(" ");
        int n=Integer.parseInt(sapera[0]);
        int m=Integer.parseInt(sapera[1]);
        Solution s=new Solution();
        s.caaal(n,m,br);
        br.close();
    }

    private void caaal(int n, int m, BufferedReader br) throws IOException {
        // TODO Auto-generated method stub
        String[] vert=br.readLine().split(" ");
        BinaryTree[] b=new BinaryTree[n+1];
        b[0]=new BinaryTree();
        for(int i=1;i<=n;i++)
        {
            b[i]=new BinaryTree();
            b[i].cat=Integer.parseInt(vert[i-1]);
            //b[i].vert=i;
        }

        for(int i=0;i<n-1;i++)
        {
             String[] s=br.readLine().split(" ");
             b[Integer.parseInt(s[0])].ar.add(b[Integer.parseInt(s[1])]);
        }

        int count=0;
        int temp;
        int bbb=(b[1].cat==0?0:1);
        for(BinaryTree bb: b[1].ar)
        {
            //System.out.println(bb.vert);
            temp=recur(bb,bbb,m);
            count+=temp;
        }
        System.out.println(count);
    }

    private int recur(BinaryTree bb, int i,int m) {
        // TODO Auto-generated method stub

        if(bb==null)
            return 0;

        if(i>m)
            return 0;

        if(bb.cat==1)
            i++;
        else
            i=0;

        if(!bb.ar.isEmpty())
        {
                int temp,count=0;
                for(BinaryTree bbb: bb.ar)
                {
                    temp=recur(bbb,i,m);
                    count+=temp;
                }
                return count;
        }
        else
        {if(i>m) return 0;}
        return 1;
    }

    public class BinaryTree
    {
        int cat;
        //int vert;
        ArrayList<BinaryTree> ar=new ArrayList<BinaryTree>();
    }
}


import java.io.*;
import java.util.*;

public class Solution
{
    public static void main(String args[] ) throws Exception
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        String[] sapera=br.readLine().split(" ");
        int n=Integer.parseInt(sapera[0]);
        int m=Integer.parseInt(sapera[1]);
        Solution s=new Solution();
        s.caaal(n,m,br);
        br.close();
    }

    private void caaal(int n, int m, BufferedReader br) throws IOException {
        // TODO Auto-generated method stub
        String[] vert=br.readLine().split(" ");
        BinaryTree[] b=new BinaryTree[n+1];
        b[0]=new BinaryTree();
        for(int i=1;i<=n;i++)
        {
            b[i]=new BinaryTree();
            b[i].cat=Integer.parseInt(vert[i-1]);
            b[i].vert=i;
        }

        for(int i=0;i<n-1;i++)
        {
             String[] s=br.readLine().split(" ");
             b[Integer.parseInt(s[0])].ar.add(b[Integer.parseInt(s[1])]);
        }

        int count=0;
        int temp;
        int bbb=(b[1].cat==0?0:1);
        for(BinaryTree bb: b[1].ar)
        {
            //System.out.println(bb.vert);
            temp=recur(bb,bbb,m);
            count+=temp;
        }
        System.out.println(count);
    }

    private int recur(BinaryTree bb, int i,int m) {
        // TODO Auto-generated method stub

        if(i>m)
            return 0;

        if(bb.cat==1)
            i++;
        else
            i=0;

        if(!bb.ar.isEmpty())
        {
                int temp,count=0;
                for(BinaryTree bbb: bb.ar)
                {
                    temp=recur(bbb,i,m);
                    count+=temp;
                }
                return count;
        }

        else
        {if(i>m) return 0;}
        System.out.println(bb.vert);
        return 1;

    }

    public class BinaryTree
    {
        int cat;
        int vert;
        ArrayList<BinaryTree> ar=new ArrayList<BinaryTree>();
    }
}


import java.io.*;
import java.util.*;

public class Solution
{
    public static void main(String args[] ) throws Exception
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        String[] sapera=br.readLine().split(" ");
        int n=Integer.parseInt(sapera[0]);
        int m=Integer.parseInt(sapera[1]);
        Solution s=new Solution();
        s.caaal(n,m,br);
        br.close();
    }

    private void caaal(int n, int m, BufferedReader br) throws IOException {
        // TODO Auto-generated method stub
        String[] vert=br.readLine().split(" ");
        BinaryTree[] b=new BinaryTree[n+1];
        b[0]=new BinaryTree();
        for(int i=1;i<=n;i++)
        {
            b[i]=new BinaryTree();
            b[i].cat=Integer.parseInt(vert[i-1]);
            //b[i].vert=i;
        }

        for(int i=0;i<n-1;i++)
        {
             String[] s=br.readLine().split(" ");
             b[Integer.parseInt(s[0])].ar.add(b[Integer.parseInt(s[1])]);
        }

        int count=0;
        int temp;
        int bbb=(b[1].cat==0?0:1);
        for(BinaryTree bb: b[1].ar)
        {
            //System.out.println(bb.vert);
            temp=recur(bb,bbb,m);
            count+=temp;
        }
        System.out.println(count);
    }

    private int recur(BinaryTree bb, int i,int m) {
        // TODO Auto-generated method stub

        if(i>m)
            return 0;

        if(bb.cat==1)
            i++;
        else
            i=0;

        if(!bb.ar.isEmpty())
        {
                int temp,count=0;
                for(BinaryTree bbb: bb.ar)
                {
                    temp=recur(bbb,i,m);
                    count+=temp;
                }
                return count;
        }

        else
        {if(i>m) return 0;}
        //System.out.println(bb.vert);
        return 1;

    }

    public class BinaryTree
    {
        int cat;
        //int vert;
        ArrayList<BinaryTree> ar=new ArrayList<BinaryTree>();
    }
}