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

public class Solution {

    private static int n, m, cnt;
    private static boolean[] cat;
    private static Map<Integer, List<Integer>> adjacency;

    private static void dfs(int cur, int prev, int catCnt) {
        if (cat[cur]) {
            catCnt++;
            if (catCnt > m) return;
        } else
            catCnt = 0;

        List<Integer> list = adjacency.get(cur);
        if (list.size() == 1 && list.get(0) == prev) {
            cnt++;
            return;
        }

        for (Integer i: list)
            if (i != prev) dfs(i, cur, catCnt);
    }

    private static void solve(InputReader in, OutputWriter out) {
        n = in.nextInt();
        m = in.nextInt();

        cat = new boolean[n + 1];
        for (int i = 1; i <= n; i++)
            if (in.nextInt() == 1) cat[i] = true;

        adjacency = new HashMap<Integer, List<Integer>>();
        int x, y;

        for (int i = 0; i < n - 1; i++) {
            x = in.nextInt();
            y = in.nextInt();

            if (!adjacency.containsKey(x)) adjacency.put(x, new ArrayList<Integer>());
            if (!adjacency.containsKey(y)) adjacency.put(y, new ArrayList<Integer>());

            adjacency.get(x).add(y);
            adjacency.get(y).add(x);
        }

        cnt = 0;
        dfs(1, 0, 0);
        out.print(cnt);
    }

    public static void main(String[] args) {
        InputReader in = new InputReader(System.in);
        OutputWriter out = new OutputWriter(System.out);
        solve(in, out);
        in.close();
        out.close();
    }

    private static class InputReader {
        private BufferedReader br;
        private StringTokenizer st;

        InputReader(InputStream is) {
            br = new BufferedReader(new InputStreamReader(is));
            st = null;
        }

        String nextLine() {
            String line = null;
            try {
                line = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return line;
        }

        String next() {
            while (st == null || !st.hasMoreTokens()) {
                String line = nextLine();
                if (line == null) return null;
                st = new StringTokenizer(line);
            }
            return st.nextToken();
        }

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

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

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

        void close() {
            try {
                br.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    private static class OutputWriter {
        BufferedWriter bw;

        OutputWriter(OutputStream os) {
            bw = new BufferedWriter(new OutputStreamWriter(os));
        }

        void print(int i) {
            print(Integer.toString(i));
        }

        void println(int i) {
            println(Integer.toString(i));
        }

        void print(long l) {
            print(Long.toString(l));
        }

        void println(long l) {
            println(Long.toString(l));
        }

        void print(double d) {
            print(Double.toString(d));
        }

        void println(double d) {
            println(Double.toString(d));
        }

        void print(boolean b) {
            print(Boolean.toString(b));
        }

        void println(boolean b) {
            println(Boolean.toString(b));
        }

        void print(char c) {
            try {
                bw.write(c);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        void println(char c) {
            println(Character.toString(c));
        }

        void print(String s) {
            try {
                bw.write(s);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        void println(String s) {
            print(s);
            print('\n');
        }

        void close() {
            try {
                bw.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}


import java.io.*;
import java.math.BigInteger;
import java.util.*;

/**
 * Created by paulp on 9/23/2015.
 */
public class Program {
    static InputReader I = new InputReader(System.in);
    static PrintWriter O = new PrintWriter(System.out);

    static class Digraph{
        private int V;
        private List<Integer>[] adjList;
        public Digraph(int V){
            this.V = V;
            adjList = new List[V];
            for(int i = 0; i < V; ++i){
                adjList[i] = new ArrayList<>();
            }
        }
        public void addEdge(int v, int w){
            adjList[v].add(w);
            adjList[w].add(v);
        }
        public Iterable<Integer> adj(int v){
            return adjList[v];
        }
        public int V(){return V;}
    }

    static class Degrees{
        private boolean[] marked;
        private int[] outdegree;
        List<Integer> sinks;
        public Degrees(Digraph g){
            marked = new boolean[g.V()];
            outdegree = new int[g.V()];

            dfs(g, 1);
            sinks = new ArrayList<>();
            for(int i = 1; i < g.V(); ++i){
                if(outdegree[i] == 0){
                    sinks.add(i);
                }
            }
        }
        private void dfs(Digraph g, int v){
            marked[v] = true;
            for(int x : g.adj(v)){
                if(!marked[x]){
                    outdegree[v]++;
                    dfs(g,x);
                }
            }
        }
        public Iterable<Integer> sinks(){
            return sinks;
        }
    }

    public static void main(String[] args) {

        int vertexCount = I.nextInt(), catVertexCount = I.nextInt();

        Digraph g = new Digraph(vertexCount + 1);

        boolean[] catPos = new boolean[vertexCount + 1];
        for(int i = 1; i <= vertexCount; ++i) if (I.nextInt() == 1) catPos[i] = true; else catPos[i] = false;

        for(int i = 0; i < vertexCount - 1; ++i){
            g.addEdge(I.nextInt(), I.nextInt());
        }

        boolean[] marked = new boolean[vertexCount + 1];
        Queue<Integer> Q = new ArrayDeque<>();
        int[] catsTo = new int[vertexCount + 1];

        int[] parent = new int[vertexCount + 1];

        Q.add(1);
        while(!Q.isEmpty()){
            int deqqed = Q.poll();
            marked[deqqed] = true;
            if(catPos[deqqed]) catsTo[deqqed]++;
            for(int x : g.adj(deqqed)){
                if(!marked[x]){
                    Q.add(x);
                    parent[x] = deqqed;
                }
            }
        }

        Degrees deg = new Degrees(g);
        int ans = 0;
        for(int x : deg.sinks()){
            int max = 0;
            int count = 0;
//            System.out.println("\nPath");
            for(int i = x; i != parent[i]; i = parent[i]){
                //System.out.print(i + " - ");
                if(catPos[i]) count++;
                else{
                    max = Math.max(count, max);
                    count = 0;
                }
            }
            max = Math.max(max, count);
            //System.out.println("max: " + max);
            if(max <= catVertexCount) ans++;
        }

        O.print(ans);

        O.close();
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

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

        public int nextInt() {
            return Integer.parseInt(next());
        }
        public long nextLong(){
            return Long.parseLong(next());
        }

    }
}


import java.io.*;
import java.math.BigInteger;
import java.util.*;

public class Program {
    static InputReader I = new InputReader(System.in);
    static PrintWriter O = new PrintWriter(System.out);

    static List<Integer>[] G;
    static int[] isCat;
    static int[] catCount;
    static int m;
    static int ans = 0;
    static boolean[] vis;

    static void dfs(int v) {
        vis[v] = true;
        if (catCount[v] > m) {
            return;
        }
        int cnt = 0;
        for (int x : G[v]) {
            if (!vis[x]) {
                catCount[x] = catCount[v] + isCat[x];
                if (isCat[x] == 0) catCount[x] = 0;
                dfs(x);
                cnt++;
            }
        }
        if(cnt == 0) ans++;
    }

    public static void main(String[] args) {

        int n = I.nextInt();
        m = I.nextInt();
        G = new ArrayList[n];
        isCat = new int[n];
        vis = new boolean[n];
        catCount = new int[n];
        for (int i = 0; i < n; ++i) {
            isCat[i] = I.nextInt();
            G[i] = new ArrayList<>();
        }

        for (int i = 0; i < n - 1; ++i) {
            int v = I.nextInt();
            int u = I.nextInt();
            u--;
            v--;
            G[v].add(u);
            G[u].add(v);
        }
        catCount[0] = isCat[0];
        dfs(0);

        O.print(ans);

        O.close();
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

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

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

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

    }
}


import java.io.*;
import java.math.BigInteger;
import java.util.*;

/**
 * Created by paulp on 9/23/2015.
 */
public class Program {
    static InputReader I = new InputReader(System.in);
    static PrintWriter O = new PrintWriter(System.out);

    static class Digraph{
        private int V;
        private List<Integer>[] adjList;
        public Digraph(int V){
            this.V = V;
            adjList = new List[V];
            for(int i = 0; i < V; ++i){
                adjList[i] = new ArrayList<>();
            }
        }
        public void addEdge(int v, int w){
            adjList[v].add(w);
        }
        public Iterable<Integer> adj(int v){
            return adjList[v];
        }
        public int V(){return V;}
    }

    static class Degrees{
        private boolean[] marked;
        private int[] outdegree;
        List<Integer> sinks;
        public Degrees(Digraph g){
            marked = new boolean[g.V()];
            outdegree = new int[g.V()];

            dfs(g, 1);
            sinks = new ArrayList<>();
            for(int i = 1; i < g.V(); ++i){
                if(outdegree[i] == 0){
                    sinks.add(i);
                }
            }
        }
        private void dfs(Digraph g, int v){
            marked[v] = true;
            for(int x : g.adj(v)){
                if(!marked[x]){
                    outdegree[v]++;
                    dfs(g,x);
                }
            }
        }
        public Iterable<Integer> sinks(){
            return sinks;
        }
    }

    public static void main(String[] args) {

        int vertexCount = I.nextInt(), catVertexCount = I.nextInt();

        Digraph g = new Digraph(vertexCount + 1);

        boolean[] catPos = new boolean[vertexCount + 1];
        for(int i = 1; i <= vertexCount; ++i) if (I.nextInt() == 1) catPos[i] = true; else catPos[i] = false;

        for(int i = 0; i < vertexCount - 1; ++i){
            g.addEdge(I.nextInt(), I.nextInt());
        }

        boolean[] marked = new boolean[vertexCount + 1];
        Queue<Integer> Q = new ArrayDeque<>();
        int[] catsTo = new int[vertexCount + 1];

        int[] parent = new int[vertexCount + 1];

        Q.add(1);
        while(!Q.isEmpty()){
            int deqqed = Q.poll();
            marked[deqqed] = true;
            if(catPos[deqqed]) catsTo[deqqed]++;
            for(int x : g.adj(deqqed)){
                if(!marked[x]){
                    Q.add(x);
                    parent[x] = deqqed;
                }
            }
        }

        Degrees deg = new Degrees(g);
        int ans = 0;
        for(int x : deg.sinks()){
            int max = 0;
            int count = 0;
//            System.out.println("\nPath");
            for(int i = x; i != parent[i]; i = parent[i]){
                //System.out.print(i + " - ");
                if(catPos[i]) count++;
                else{
                    max = Math.max(count, max);
                    count = 0;
                }
            }
            max = Math.max(max, count);
            //System.out.println("max: " + max);
            if(max <= catVertexCount) ans++;
        }

        O.print(ans);

        O.close();
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

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

        public int nextInt() {
            return Integer.parseInt(next());
        }
        public long nextLong(){
            return Long.parseLong(next());
        }

    }
}


import java.io.*;
import java.math.BigInteger;
import java.util.*;

/**
 * Created by paulp on 9/23/2015.
 */
public class Program {
    static InputReader I = new InputReader(System.in);
    static PrintWriter O = new PrintWriter(System.out);

    static List<Integer>[] G;
    static int[] isCat;
    static int[] catCount;
    static int m;
    static int ans = 0;
    static boolean[] vis;

    static void dfs(int v){
        vis[v] = true;
        if(catCount[v] > m) {/*ans++;*/return;}
        int cnt = 0;
        for(int x : G[v]){
            if(!vis[x]){
                catCount[x] = catCount[v] + isCat[x];
                if(isCat[v] == 0) catCount[x] = 0;
                dfs(x);
            } else{
                cnt++;
            }
        }
        if(G[v].size() == cnt && catCount[v] <= m) ans++;
    }

    public static void main(String[] args) {

        int n = I.nextInt();
        m = I.nextInt();
        G = new ArrayList[n];
        isCat = new int[n];
        vis = new boolean[n];
        catCount = new int[n];
        for (int i = 0; i < n; ++i){ isCat[i] = I.nextInt(); G[i] = new ArrayList<>();}

        for(int i = 0; i < n - 1; ++i){
            int v = I.nextInt();
            int u = I.nextInt();
            u--;v--;
            G[v].add(u);
            G[u].add(v);
        }
        catCount[0] = isCat[0];
        dfs(0);
        O.print(ans);
        O.close();
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

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

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

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

    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

public class C {

    private static class v {

        boolean cat;
        ArrayList<v> c = new ArrayList<>();

        public v(boolean cat) {
            this.cat = cat;
        }
    }

    private static int bfs(v node, int currM, int m, v par) {
        if (node.cat) {
            currM++;
        } else {
            currM = 0;
        }
        if (currM > m) {
            return 0;
        } else {
            if (par == null || node.c.size() > 1) {
                int sum = 0;
                for (v ch : node.c) {
                    if (par == null || !ch.equals(par)) {
                        sum += bfs(ch, currM, m, node);
                    }
                }
                return sum;
            } else {
                return 1;
            }
        }
    }

    public static void main(String[] args) {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        try {
            String[] as = br.readLine().split(" ");
            int n = Integer.parseInt(as[0]);
            int m = Integer.parseInt(as[1]);
            as = br.readLine().split(" ");
            v[] vs = new v[n + 1];
            for (int i = 0; i < n; i++) {
                if (as[i].equals("1")) {
                    vs[i + 1] = new v(true);
                } else {
                    vs[i + 1] = new v(false);
                }
            }
            for (int i = 0; i < n - 1; i++) {
                as = br.readLine().split(" ");
                vs[Integer.parseInt(as[0])].c.add(vs[Integer.parseInt(as[1])]);
                vs[Integer.parseInt(as[1])].c.add(vs[Integer.parseInt(as[0])]);
            }
            System.out.println(bfs(vs[1], 0, m, null));
        } catch (IOException ex) {

        }
    }

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

public class C {

    private static class v {

        boolean cat;
        ArrayList<v> c = new ArrayList<>();

        public v(boolean cat) {
            this.cat = cat;
        }
    }

    private static int bfs(v node, int currM, int m) {
        if (node.cat) {
            currM++;
        } else {
            currM = 0;
        }
        if (currM > m) {
            return 0;
        } else {
            if (node.c.size() > 0) {
                int sum = 0;
                for (v ch : node.c) {
                    sum += bfs(ch, currM, m);
                }
                return sum;
            } else {
                return 1;
            }
        }
    }

    public static void main(String[] args) {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        try {
            String[] as = br.readLine().split(" ");
            int n = Integer.parseInt(as[0]);
            int m = Integer.parseInt(as[1]);
            as = br.readLine().split(" ");
            v[] vs = new v[n + 1];
            for (int i = 0; i < n; i++) {
                if (as[i].equals("1")) {
                    vs[i + 1] = new v(true);
                } else {
                    vs[i + 1] = new v(false);
                }
            }
            for (int i = 0; i < n - 1; i++) {
                as = br.readLine().split(" ");
                vs[Integer.parseInt(as[0])].c.add(vs[Integer.parseInt(as[1])]);
            }
            System.out.println(bfs(vs[1], 0, m));
        } catch (IOException ex) {

        }
    }

}


/**
 * Created by Grand on 27.07.2015.
 */

import java.io.*;
import java.util.ArrayList;
import java.util.Locale;
import java.util.StringTokenizer;

public class Main implements Runnable {

    final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;

    BufferedReader in;
    PrintWriter out;
    StringTokenizer tok = new StringTokenizer("");

    public static void main(String[] args) {
        new Thread(null, new Main(), "", 128 * (1L << 20)).start();

    }

    void init() throws FileNotFoundException {
        Locale.setDefault(Locale.US);
        /*if(ONLINE_JUDGE){
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
        }else {
            in = new BufferedReader(new FileReader("INPUT.TXT"));
            out = new PrintWriter("OUTPUT.TXT");
        }*/

        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
    }

    long timeBegin, timeEnd;

    void time() {
        timeEnd = System.currentTimeMillis();
        System.err.println("Time = " + (timeEnd - timeBegin));
    }

    public void run() {
        try {
            timeBegin = System.currentTimeMillis();

            init();
            solve();

            out.close();
            time();
        } catch (Exception e) {
            e.printStackTrace(System.err);
            System.exit(-1);
        }
    }

    String readString() throws IOException {

        while (!tok.hasMoreTokens()) {
            try {
                tok = new StringTokenizer(in.readLine());
            } catch (Exception e) {
                return null;
            }
        }
        return tok.nextToken();
    }

    String readString(String s) throws IOException {
        while (!tok.hasMoreTokens()) {
            try {
                tok = new StringTokenizer(in.readLine(), s + "\n \t");
            } catch (Exception e) {
                return null;
            }
        }
        return tok.nextToken();
    }

    double readDouble() throws IOException {
        return Double.parseDouble(readString());
    }

    int readInt() throws IOException {
        return Integer.parseInt(readString());
    }

    long readLong() throws IOException {
        return Long.parseLong(readString());
    }

    int readInt(String s) throws IOException {
        return Integer.parseInt(readString(s));
    }

    boolean isPrime(int a) throws IOException {
        int del = 0;
        if (a == 2) {
            return true;
        }
        for (int i = 2; i < Math.sqrt(a) + 1; i++) {
            if (a % i == 0) {
                del = i;
                break;
            }
        }
        if (del > 0) {
            return false;
        } else return true;
    }

    public long factorial(int num) throws IOException {
        long res = 1;
        for (int i = 2; i <= num; i++) {
            res *= i;
        }
        return res;
    }
    public int[] readIntArr(int n) throws IOException {
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = readInt();
        }
        return a;
    }

    public class pair implements Comparable<pair>{
        long money, value;
        public pair(int money, int value){
            this.money = money;
            this.value = value;
        }

        @Override
        public int compareTo(pair pair) {
            if(pair.money>this.money){
                return -1;
            }return 1;
        }
    }
    int res = 0;

    void solve() throws Exception{
        int n=readInt();
        int m=readInt();
        int[] cat = readIntArr(n);
        ArrayList<Integer>[] graph = new ArrayList[n];
        for (int i = 0; i < n; i++) {
            graph[i]=new ArrayList<Integer>();
        }
        for (int i = 0; i < n-1; i++) {
            int from = readInt()-1;
            int to = readInt()-1;
            graph[from].add(to);
        }
        if(cat[0]==1) {
            dfs(graph, 1, cat, 0, m);
        }else{
            dfs(graph, 0, cat, 0, m);
        }
        System.out.println(res);

    }

    public void dfs(ArrayList<Integer>[] graph, int currCat, int[] cats, int curr,int maxCat){
        if(graph[curr].size()==0){
            res++;
        }
        for (int i = 0; i < graph[curr].size(); i++) {
            if(cats[graph[curr].get(i)]==1){
                if(currCat+1>maxCat)continue;
                else {
                    dfs(graph, currCat+1, cats, graph[curr].get(i),maxCat);
                }
            }
            else{
                dfs(graph, 0, cats, graph[curr].get(i), maxCat);
            }
        }
    }

}


/**
 * Created by Grand on 27.07.2015.
 */

import java.io.*;
import java.util.ArrayList;
import java.util.Locale;
import java.util.StringTokenizer;

public class Main implements Runnable {

    final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;

    BufferedReader in;
    PrintWriter out;
    StringTokenizer tok = new StringTokenizer("");

    public static void main(String[] args) {
        new Thread(null, new Main(), "", 128 * (1L << 20)).start();

    }

    void init() throws FileNotFoundException {
        Locale.setDefault(Locale.US);
        /*if(ONLINE_JUDGE){
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
        }else {
            in = new BufferedReader(new FileReader("INPUT.TXT"));
            out = new PrintWriter("OUTPUT.TXT");
        }*/

        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
    }

    long timeBegin, timeEnd;

    void time() {
        timeEnd = System.currentTimeMillis();
        System.err.println("Time = " + (timeEnd - timeBegin));
    }

    public void run() {
        try {
            timeBegin = System.currentTimeMillis();

            init();
            solve();

            out.close();
            time();
        } catch (Exception e) {
            e.printStackTrace(System.err);
            System.exit(-1);
        }
    }

    String readString() throws IOException {

        while (!tok.hasMoreTokens()) {
            try {
                tok = new StringTokenizer(in.readLine());
            } catch (Exception e) {
                return null;
            }
        }
        return tok.nextToken();
    }

    String readString(String s) throws IOException {
        while (!tok.hasMoreTokens()) {
            try {
                tok = new StringTokenizer(in.readLine(), s + "\n \t");
            } catch (Exception e) {
                return null;
            }
        }
        return tok.nextToken();
    }

    double readDouble() throws IOException {
        return Double.parseDouble(readString());
    }

    int readInt() throws IOException {
        return Integer.parseInt(readString());
    }

    long readLong() throws IOException {
        return Long.parseLong(readString());
    }

    int readInt(String s) throws IOException {
        return Integer.parseInt(readString(s));
    }

    boolean isPrime(int a) throws IOException {
        int del = 0;
        if (a == 2) {
            return true;
        }
        for (int i = 2; i < Math.sqrt(a) + 1; i++) {
            if (a % i == 0) {
                del = i;
                break;
            }
        }
        if (del > 0) {
            return false;
        } else return true;
    }

    public long factorial(int num) throws IOException {
        long res = 1;
        for (int i = 2; i <= num; i++) {
            res *= i;
        }
        return res;
    }
    public int[] readIntArr(int n) throws IOException {
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = readInt();
        }
        return a;
    }

    public class pair implements Comparable<pair>{
        long money, value;
        public pair(int money, int value){
            this.money = money;
            this.value = value;
        }

        @Override
        public int compareTo(pair pair) {
            if(pair.money>this.money){
                return -1;
            }return 1;
        }
    }
    int res = 0;

    void solve() throws Exception{
        int n=readInt();
        int m=readInt();
        int[] cat = readIntArr(n);
        ArrayList<Integer>[] graph = new ArrayList[n];
        for (int i = 0; i < n; i++) {
            graph[i]=new ArrayList<Integer>();
        }
        for (int i = 0; i < n-1; i++) {
            int from = readInt()-1;
            int to = readInt()-1;
            graph[from].add(to);
        }
        if(cat[0]==1) {
            dfs(graph, 1, cat, 0, m);
        }else{
            dfs(graph, 0, cat, 0, m);
        }
        System.out.println(res);

    }

    public void dfs(ArrayList<Integer>[] graph, int currCat, int[] cats, int curr,int maxCat){
        if(graph[curr].size()==0 && currCat<=maxCat){
            res++;
        }
        for (int i = 0; i < graph[curr].size(); i++) {
            int to = graph[curr].get(i);
            if(cats[to]==1){
                if(currCat+1<=maxCat){
                    dfs(graph, currCat+1, cats, to, maxCat);
                }
            }
            else{
                dfs(graph, 0, cats, to, maxCat);
            }
        }
    }

}


import java.io.*;
import java.util.ArrayList;
import java.util.Locale;
import java.util.StringTokenizer;

public class Main implements Runnable {

    final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;

    BufferedReader in;
    PrintWriter out;
    StringTokenizer tok = new StringTokenizer("");

    public static void main(String[] args) {
        new Thread(null, new Main(), "", 128 * (1L << 20)).start();

    }

    void init() throws FileNotFoundException {
        Locale.setDefault(Locale.US);
        /*if(ONLINE_JUDGE){
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
        }else {
            in = new BufferedReader(new FileReader("INPUT.TXT"));
            out = new PrintWriter("OUTPUT.TXT");
        }*/

        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
    }

    long timeBegin, timeEnd;

    void time() {
        timeEnd = System.currentTimeMillis();
        System.err.println("Time = " + (timeEnd - timeBegin));
    }

    public void run() {
        try {
            timeBegin = System.currentTimeMillis();

            init();
            solve();

            out.close();
            time();
        } catch (Exception e) {
            e.printStackTrace(System.err);
            System.exit(-1);
        }
    }

    String readString() throws IOException {

        while (!tok.hasMoreTokens()) {
            try {
                tok = new StringTokenizer(in.readLine());
            } catch (Exception e) {
                return null;
            }
        }
        return tok.nextToken();
    }

    String readString(String s) throws IOException {
        while (!tok.hasMoreTokens()) {
            try {
                tok = new StringTokenizer(in.readLine(), s + "\n \t");
            } catch (Exception e) {
                return null;
            }
        }
        return tok.nextToken();
    }

    double readDouble() throws IOException {
        return Double.parseDouble(readString());
    }

    int readInt() throws IOException {
        return Integer.parseInt(readString());
    }

    long readLong() throws IOException {
        return Long.parseLong(readString());
    }

    int readInt(String s) throws IOException {
        return Integer.parseInt(readString(s));
    }

    boolean isPrime(int a) throws IOException {
        int del = 0;
        if (a == 2) {
            return true;
        }
        for (int i = 2; i < Math.sqrt(a) + 1; i++) {
            if (a % i == 0) {
                del = i;
                break;
            }
        }
        if (del > 0) {
            return false;
        } else return true;
    }

    public long factorial(int num) throws IOException {
        long res = 1;
        for (int i = 2; i <= num; i++) {
            res *= i;
        }
        return res;
    }
    public int[] readIntArr(int n) throws IOException {
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = readInt();
        }
        return a;
    }

    public class pair implements Comparable<pair>{
        long money, value;
        public pair(int money, int value){
            this.money = money;
            this.value = value;
        }

        @Override
        public int compareTo(pair pair) {
            if(pair.money>this.money){
                return -1;
            }return 1;
        }
    }
    static int res = 0;
    boolean[] used;

    void solve() throws Exception{
        int n=readInt();
        int m=readInt();
        used = new boolean[n];
        int[] cat = readIntArr(n);
        ArrayList<Integer>[] graph = new ArrayList[n];
        for (int i = 0; i < n; i++) {
            graph[i]=new ArrayList<Integer>();
        }
        for (int i = 0; i < n-1; i++) {
            int from = readInt()-1;
            int to = readInt()-1;
            graph[from].add(to);
            graph[to].add(from);
        }
        if(cat[0]==1) {
            dfs(graph, 1, cat, 0, m, -1);
        }else{
            dfs(graph, 0, cat, 0, m, -1);
        }
        System.out.println(res);

    }

    public void dfs(ArrayList<Integer>[] graph, int currCat, int[] cats, int curr, int maxCat, int prev){
        used[curr]=true;
        if(graph[curr].size()==1){
            res++;
            return;
        }
        for (int i = 0; i < graph[curr].size(); i++) {
            int to = graph[curr].get(i);
            if(used[to])continue;
            if(cats[to]==1){
                int cCat = currCat+1;
                if(cCat<=maxCat){
                    dfs(graph, cCat, cats, to, maxCat, curr);
                }
            }
            else{
                dfs(graph, 0, cats, to, maxCat, curr);
            }
        }
    }

}


/**
 * Created by Grand on 27.07.2015.
 */

import java.io.*;
import java.util.ArrayList;
import java.util.Locale;
import java.util.StringTokenizer;

public class Main implements Runnable {

    final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;

    BufferedReader in;
    PrintWriter out;
    StringTokenizer tok = new StringTokenizer("");

    public static void main(String[] args) {
        new Thread(null, new Main(), "", 128 * (1L << 20)).start();

    }

    void init() throws FileNotFoundException {
        Locale.setDefault(Locale.US);
        /*if(ONLINE_JUDGE){
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
        }else {
            in = new BufferedReader(new FileReader("INPUT.TXT"));
            out = new PrintWriter("OUTPUT.TXT");
        }*/

        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
    }

    long timeBegin, timeEnd;

    void time() {
        timeEnd = System.currentTimeMillis();
        System.err.println("Time = " + (timeEnd - timeBegin));
    }

    public void run() {
        try {
            timeBegin = System.currentTimeMillis();

            init();
            solve();

            out.close();
            time();
        } catch (Exception e) {
            e.printStackTrace(System.err);
            System.exit(-1);
        }
    }

    String readString() throws IOException {

        while (!tok.hasMoreTokens()) {
            try {
                tok = new StringTokenizer(in.readLine());
            } catch (Exception e) {
                return null;
            }
        }
        return tok.nextToken();
    }

    String readString(String s) throws IOException {
        while (!tok.hasMoreTokens()) {
            try {
                tok = new StringTokenizer(in.readLine(), s + "\n \t");
            } catch (Exception e) {
                return null;
            }
        }
        return tok.nextToken();
    }

    double readDouble() throws IOException {
        return Double.parseDouble(readString());
    }

    int readInt() throws IOException {
        return Integer.parseInt(readString());
    }

    long readLong() throws IOException {
        return Long.parseLong(readString());
    }

    int readInt(String s) throws IOException {
        return Integer.parseInt(readString(s));
    }

    boolean isPrime(int a) throws IOException {
        int del = 0;
        if (a == 2) {
            return true;
        }
        for (int i = 2; i < Math.sqrt(a) + 1; i++) {
            if (a % i == 0) {
                del = i;
                break;
            }
        }
        if (del > 0) {
            return false;
        } else return true;
    }

    public long factorial(int num) throws IOException {
        long res = 1;
        for (int i = 2; i <= num; i++) {
            res *= i;
        }
        return res;
    }
    public int[] readIntArr(int n) throws IOException {
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = readInt();
        }
        return a;
    }

    public class pair implements Comparable<pair>{
        long money, value;
        public pair(int money, int value){
            this.money = money;
            this.value = value;
        }

        @Override
        public int compareTo(pair pair) {
            if(pair.money>this.money){
                return -1;
            }return 1;
        }
    }
    int res = 0;

    void solve() throws Exception{
        int n=readInt();
        int m=readInt();
        int[] cat = readIntArr(n);
        ArrayList<Integer>[] graph = new ArrayList[n];
        for (int i = 0; i < n; i++) {
            graph[i]=new ArrayList<Integer>();
        }
        for (int i = 0; i < n-1; i++) {
            int from = readInt()-1;
            int to = readInt()-1;
            graph[from].add(to);
        }
        dfs(graph, 0, cat, 0, m);
        System.out.println(res);

    }

    public void dfs(ArrayList<Integer>[] graph, int currCat, int[] cats, int curr,int maxCat){
        if(graph[curr].size()==0){
            res++;
        }
        for (int i = 0; i < graph[curr].size(); i++) {
            if(cats[graph[curr].get(i)]==1){
                if(currCat+1>=maxCat)continue;
                else {
                    dfs(graph, currCat+1, cats, graph[curr].get(i),maxCat);
                }
            }
            else{
                dfs(graph, 0, cats, graph[curr].get(i), maxCat);
            }
        }
    }

}


/**
 * Created by Grand on 27.07.2015.
 */

import java.io.*;
import java.util.ArrayList;
import java.util.Locale;
import java.util.StringTokenizer;

public class Main implements Runnable {

    final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;

    BufferedReader in;
    PrintWriter out;
    StringTokenizer tok = new StringTokenizer("");

    public static void main(String[] args) {
        new Thread(null, new Main(), "", 128 * (1L << 20)).start();

    }

    void init() throws FileNotFoundException {
        Locale.setDefault(Locale.US);
        /*if(ONLINE_JUDGE){
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
        }else {
            in = new BufferedReader(new FileReader("INPUT.TXT"));
            out = new PrintWriter("OUTPUT.TXT");
        }*/

        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
    }

    long timeBegin, timeEnd;

    void time() {
        timeEnd = System.currentTimeMillis();
        System.err.println("Time = " + (timeEnd - timeBegin));
    }

    public void run() {
        try {
            timeBegin = System.currentTimeMillis();

            init();
            solve();

            out.close();
            time();
        } catch (Exception e) {
            e.printStackTrace(System.err);
            System.exit(-1);
        }
    }

    String readString() throws IOException {

        while (!tok.hasMoreTokens()) {
            try {
                tok = new StringTokenizer(in.readLine());
            } catch (Exception e) {
                return null;
            }
        }
        return tok.nextToken();
    }

    String readString(String s) throws IOException {
        while (!tok.hasMoreTokens()) {
            try {
                tok = new StringTokenizer(in.readLine(), s + "\n \t");
            } catch (Exception e) {
                return null;
            }
        }
        return tok.nextToken();
    }

    double readDouble() throws IOException {
        return Double.parseDouble(readString());
    }

    int readInt() throws IOException {
        return Integer.parseInt(readString());
    }

    long readLong() throws IOException {
        return Long.parseLong(readString());
    }

    int readInt(String s) throws IOException {
        return Integer.parseInt(readString(s));
    }

    boolean isPrime(int a) throws IOException {
        int del = 0;
        if (a == 2) {
            return true;
        }
        for (int i = 2; i < Math.sqrt(a) + 1; i++) {
            if (a % i == 0) {
                del = i;
                break;
            }
        }
        if (del > 0) {
            return false;
        } else return true;
    }

    public long factorial(int num) throws IOException {
        long res = 1;
        for (int i = 2; i <= num; i++) {
            res *= i;
        }
        return res;
    }
    public int[] readIntArr(int n) throws IOException {
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = readInt();
        }
        return a;
    }

    public class pair implements Comparable<pair>{
        long money, value;
        public pair(int money, int value){
            this.money = money;
            this.value = value;
        }

        @Override
        public int compareTo(pair pair) {
            if(pair.money>this.money){
                return -1;
            }return 1;
        }
    }
    static int res = 0;

    void solve() throws Exception{
        int n=readInt();
        int m=readInt();
        int[] cat = readIntArr(n);
        ArrayList<Integer>[] graph = new ArrayList[n];
        for (int i = 0; i < n; i++) {
            graph[i]=new ArrayList<Integer>();
        }
        for (int i = 0; i < n-1; i++) {
            int from = readInt()-1;
            int to = readInt()-1;
            graph[from].add(to);
        }
        if(cat[0]==1) {
            dfs(graph, 1, cat, 0, m);
        }else{
            dfs(graph, 0, cat, 0, m);
        }
        System.out.println(res);

    }

    public void dfs(ArrayList<Integer>[] graph, int currCat, int[] cats, int curr, int maxCat){
        if(graph[curr].isEmpty()){
            res++;
        }
        for (int i = 0; i < graph[curr].size(); i++) {
            int to = graph[curr].get(i);
            if(cats[to]==1){
                int cCat = currCat+1;
                if(cCat<=maxCat){
                    dfs(graph, cCat, cats, to, maxCat);
                }
            }
            else{
                dfs(graph, 0, cats, to, maxCat);
            }
        }
    }

}


import java.io.*;
import java.util.ArrayList;
import java.util.Locale;
import java.util.StringTokenizer;

public class Main implements Runnable {

    final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;

    BufferedReader in;
    PrintWriter out;
    StringTokenizer tok = new StringTokenizer("");

    public static void main(String[] args) {
        new Thread(null, new Main(), "", 128 * (1L << 20)).start();

    }

    void init() throws FileNotFoundException {
        Locale.setDefault(Locale.US);
        /*if(ONLINE_JUDGE){
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
        }else {
            in = new BufferedReader(new FileReader("INPUT.TXT"));
            out = new PrintWriter("OUTPUT.TXT");
        }*/

        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
    }

    long timeBegin, timeEnd;

    void time() {
        timeEnd = System.currentTimeMillis();
        System.err.println("Time = " + (timeEnd - timeBegin));
    }

    public void run() {
        try {
            timeBegin = System.currentTimeMillis();

            init();
            solve();

            out.close();
            time();
        } catch (Exception e) {
            e.printStackTrace(System.err);
            System.exit(-1);
        }
    }

    String readString() throws IOException {

        while (!tok.hasMoreTokens()) {
            try {
                tok = new StringTokenizer(in.readLine());
            } catch (Exception e) {
                return null;
            }
        }
        return tok.nextToken();
    }

    String readString(String s) throws IOException {
        while (!tok.hasMoreTokens()) {
            try {
                tok = new StringTokenizer(in.readLine(), s + "\n \t");
            } catch (Exception e) {
                return null;
            }
        }
        return tok.nextToken();
    }

    double readDouble() throws IOException {
        return Double.parseDouble(readString());
    }

    int readInt() throws IOException {
        return Integer.parseInt(readString());
    }

    long readLong() throws IOException {
        return Long.parseLong(readString());
    }

    int readInt(String s) throws IOException {
        return Integer.parseInt(readString(s));
    }

    boolean isPrime(int a) throws IOException {
        int del = 0;
        if (a == 2) {
            return true;
        }
        for (int i = 2; i < Math.sqrt(a) + 1; i++) {
            if (a % i == 0) {
                del = i;
                break;
            }
        }
        if (del > 0) {
            return false;
        } else return true;
    }

    public long factorial(int num) throws IOException {
        long res = 1;
        for (int i = 2; i <= num; i++) {
            res *= i;
        }
        return res;
    }
    public int[] readIntArr(int n) throws IOException {
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = readInt();
        }
        return a;
    }

    public class pair implements Comparable<pair>{
        long money, value;
        public pair(int money, int value){
            this.money = money;
            this.value = value;
        }

        @Override
        public int compareTo(pair pair) {
            if(pair.money>this.money){
                return -1;
            }return 1;
        }
    }
    static int res = 0;
    boolean[] used;

    void solve() throws Exception{
        int n=readInt();
        int m=readInt();
        used = new boolean[n];
        int[] cat = readIntArr(n);
        ArrayList<Integer>[] graph = new ArrayList[n];
        for (int i = 0; i < n; i++) {
            graph[i]=new ArrayList<Integer>();
        }
        for (int i = 0; i < n-1; i++) {
            int from = readInt()-1;
            int to = readInt()-1;
            graph[from].add(to);
            graph[to].add(from);
        }
        if(cat[0]==1) {
            dfs(graph, 1, cat, 0, m, -1);
        }else{
            dfs(graph, 0, cat, 0, m, -1);
        }
        System.out.println(res);

    }

    public void dfs(ArrayList<Integer>[] graph, int currCat, int[] cats, int curr, int maxCat, int prev){
        used[curr]=true;
        if(graph[curr].size()==1 && graph[curr].get(0)==prev){
            res++;
            return;
        }
        for (int i = 0; i < graph[curr].size(); i++) {
            int to = graph[curr].get(i);
            if(used[to])continue;
            if(cats[to]==1){
                int cCat = currCat+1;
                if(cCat<=maxCat){
                    dfs(graph, cCat, cats, to, maxCat, curr);
                }
            }
            else{
                dfs(graph, 0, cats, to, maxCat, curr);
            }
        }
    }

}


import java.util.*;
import java.io.*;
public class Major {
	static int decide[];
	static ArrayList<Integer>list[];
	static int ans = 0;
	static boolean cont = true;
	static boolean leaf[];
	static int m;
static void dfs(int start,int tot,boolean visited[]){
	visited[start] = true;
	if(decide[start] == 1 && cont)tot++;
	else if(decide[start] == 1 && !cont){
		cont = true;tot++;
	}
	else if(decide[start] == 0){
		cont = false;tot = 0;
	}
	if(tot > m)return;
	for(int temp : list[start]){
		if(!visited[temp])
			dfs(temp,tot,visited);
	}

	if(leaf[start] && tot <= m)ans++;
}
public static void main(String [] args)throws Exception{
	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	StringTokenizer st = new StringTokenizer(br.readLine());
	int n = Integer.parseInt(st.nextToken());
	 m = Integer.parseInt(st.nextToken());

	 decide = new int[n];
	st = new StringTokenizer(br.readLine());
	for(int i = 0;i < n;i++){
		decide[i] = Integer.parseInt(st.nextToken());
	}
    list = new ArrayList[n];
	for(int i = 0;i < n;i++)
		list[i] = new ArrayList<Integer>();

	boolean visited[] = new boolean[n];
	int deg[] = new int[n];
	leaf  = new boolean[n];
	for(int i = 0;i < n - 1 ;i++){
		st = new StringTokenizer(br.readLine());
		int x = Integer.parseInt(st.nextToken()) - 1;
		int y = Integer.parseInt(st.nextToken()) - 1;
		list[x].add(y);
		list[y].add(x);
		deg[x]++;
		deg[y]++;
	}
	for(int i = 0;i < n;i++)
		if(deg[i] == 1 && i != 0){
			leaf[i] = true;
		}
	dfs(0,0,visited);
	System.out.print(ans);
}
}


import java.awt.Point;
import java.io.BufferedOutputStream;
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.lang.reflect.Array;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.PriorityQueue;
import java.util.Random;
import java.util.StringTokenizer;
import static java.lang.Math.*;

/**
 *
 * @author Mojtaba
 */
public class Main {

    static int n, m;
    static boolean[] cats;
    static boolean[] visited;
    static long sum;
    static ArrayList<Edge>[] graph;

    public static void main(String[] args) throws IOException {
        MyScanner in = new MyScanner(System.in);
        PrintWriter writer = new PrintWriter(new BufferedOutputStream(System.out));
        StringBuilder sb =  new StringBuilder("");

        n = in.nextInt();
        m = in.nextInt();
        cats = new boolean[n];
        graph = new ArrayList[n];
        visited = new boolean[n];
        for (int i = 0; i < n; i++) {
            graph[i] = new ArrayList<>();
        }
        for (int i = 0; i < n; i++) {
            cats[i] = in.nextInt() == 1;
        }
        for (int i = 1; i < n; i++) {
            int from = in.nextInt() - 1;
            int to = in.nextInt() - 1;
            graph[from].add(new Edge(from, to));
        }
        DFS(0, 0, false);
        sb.append(sum);

        //System.out.println(sb.toString().trim());
        writer.println(sb.toString().trim());
        writer.flush();
        in.close();
    }

    static void sort(int[] a) {
        Random rand = new Random();
        for (int i = a.length - 1; i > 0; i--) {
            int index = rand.nextInt(i + 1);
            // Simple swap
            int temp = a[index];
            a[index] = a[i];
            a[i] = temp;
        }
        Arrays.sort(a);
    }

    private static void DFS(int vertex, int con, boolean b) {
        if (visited[vertex]) {
            return;
        }
        visited[vertex] = true;
        if (cats[vertex]) {
            con++;
        }
        if (con > m) {
            //b = true;
            return;
        }
        if (!cats[vertex]) {
            con = 0;
        }
        if (graph[vertex].isEmpty() && !b && vertex != 0) {
            sum++;
        }
        for (Edge e : graph[vertex]) {
            DFS(e.to, con, b);
        }
    }
}

class Edge {

    int from, to;

    public Edge(int from, int to) {
        this.from = from;
        this.to = to;
    }
}

class MyScanner {

    BufferedReader reader;
    StringTokenizer tokenizer;

    public MyScanner(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.awt.Point;
import java.io.BufferedOutputStream;
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.lang.reflect.Array;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.PriorityQueue;
import java.util.Random;
import java.util.StringTokenizer;
import static java.lang.Math.*;

/**
 *
 * @author Mojtaba
 */
public class Main {

    static int n, m;
    static boolean[] cats;
    static boolean[] visited;
    static long sum;
    static ArrayList<Edge>[] graph;

    public static void main(String[] args) throws IOException {
        MyScanner in = new MyScanner(System.in);
        PrintWriter writer = new PrintWriter(new BufferedOutputStream(System.out));
        StringBuilder sb = new StringBuilder("");

        n = in.nextInt();
        m = in.nextInt();
        cats = new boolean[n];
        graph = new ArrayList[n];
        visited = new boolean[n];
        for (int i = 0; i < n; i++) {
            graph[i] = new ArrayList<>();
        }
        for (int i = 0; i < n; i++) {
            cats[i] = in.nextInt() == 1;
        }
        for (int i = 1; i < n; i++) {
            int from = in.nextInt() - 1;
            int to = in.nextInt() - 1;
            graph[from].add(new Edge(from, to));
        }
        DFS(0, 0, false);
        sb.append(sum);

        //System.out.println(sb.toString().trim());
        writer.println(sb.toString().trim());
        writer.flush();
        in.close();
    }

    static void sort(int[] a) {
        Random rand = new Random();
        for (int i = a.length - 1; i > 0; i--) {
            int index = rand.nextInt(i + 1);
            // Simple swap
            int temp = a[index];
            a[index] = a[i];
            a[i] = temp;
        }
        Arrays.sort(a);
    }

    private static void DFS(int vertex, int con, boolean b) {
        if (visited[vertex]) {
            return;
        }
        if (cats[vertex]) {
            con++;
        }
        if (con > m) {
            //b = true;
            return;
        }
        if (!cats[vertex]) {
            con = 0;
        }
        if (graph[vertex].isEmpty() && !b) {
            sum++;
        }
        for (Edge e : graph[vertex]) {
            DFS(e.to, con, b);
        }
    }
}

class Edge {

    int from, to;

    public Edge(int from, int to) {
        this.from = from;
        this.to = to;
    }
}

class MyScanner {

    BufferedReader reader;
    StringTokenizer tokenizer;

    public MyScanner(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.awt.Point;
import java.io.BufferedOutputStream;
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.lang.reflect.Array;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.PriorityQueue;
import java.util.Random;
import java.util.StringTokenizer;
import static java.lang.Math.*;

/**
 *
 * @author Mojtaba
 */
public class Main {

    static int n, m;
    static boolean[] cats;
    static boolean[] visited;
    static long sum;
    static ArrayList<Edge>[] graph;

    public static void main(String[] args) throws IOException {
        MyScanner in = new MyScanner(System.in);
        PrintWriter writer = new PrintWriter(new BufferedOutputStream(System.out));
        StringBuilder sb = new StringBuilder("");

        n = in.nextInt();
        m = in.nextInt();
        cats = new boolean[n];
        graph = new ArrayList[n];
        visited = new boolean[n];
        for (int i = 0; i < n; i++) {
            graph[i] = new ArrayList<>();
        }
        for (int i = 0; i < n; i++) {
            cats[i] = in.nextInt() == 1;
        }
        for (int i = 1; i < n; i++) {
            int from = in.nextInt() - 1;
            int to = in.nextInt() - 1;
            graph[from].add(new Edge(from, to));
            graph[to].add(new Edge(to, from));
        }
        DFS(0, 0, false);
        sb.append(sum);

        //System.out.println(sb.toString().trim());
        writer.println(sb.toString().trim());
        writer.flush();
        in.close();
    }

    static void sort(int[] a) {
        Random rand = new Random();
        for (int i = a.length - 1; i > 0; i--) {
            int index = rand.nextInt(i + 1);
            // Simple swap
            int temp = a[index];
            a[index] = a[i];
            a[i] = temp;
        }
        Arrays.sort(a);
    }

    private static void DFS(int vertex, int con, boolean b) {
        if (visited[vertex]) {
            return;
        }
        visited[vertex] = true;
        if (cats[vertex]) {
            con++;
        }
        if (con > m) {
            //b = true;
            return;
        }
        if (!cats[vertex]) {
            con = 0;
        }
        if (graph[vertex].size() == 1 && !b && vertex != 0) {
            sum++;
        }
        for (Edge e : graph[vertex]) {
            if (e.to != vertex) {
                DFS(e.to, con, b);
            }
        }
    }
}

class Edge {

    int from, to;

    public Edge(int from, int to) {
        this.from = from;
        this.to = to;
    }
}

class MyScanner {

    BufferedReader reader;
    StringTokenizer tokenizer;

    public MyScanner(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.awt.Point;
import java.io.BufferedOutputStream;
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.lang.reflect.Array;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.PriorityQueue;
import java.util.Random;
import java.util.StringTokenizer;
import static java.lang.Math.*;

/**
 *
 * @author Mojtaba
 */
public class Main {

    static int n, m;
    static boolean[] cats;
    static boolean[] visited;
    static long sum;
    static ArrayList<Edge>[] graph;

    public static void main(String[] args) throws IOException {
        MyScanner in = new MyScanner(System.in);
        PrintWriter writer = new PrintWriter(new BufferedOutputStream(System.out));
        StringBuilder sb = new StringBuilder("");

        n = in.nextInt();
        m = in.nextInt();
        cats = new boolean[n];
        graph = new ArrayList[n];
        visited = new boolean[n];
        for (int i = 0; i < n; i++) {
            graph[i] = new ArrayList<>();
        }
        for (int i = 0; i < n; i++) {
            cats[i] = in.nextInt() == 1;
        }
        for (int i = 1; i < n; i++) {
            int from = in.nextInt() - 1;
            int to = in.nextInt() - 1;
            graph[from].add(new Edge(from, to));
            graph[to].add(new Edge(to, from));
        }
        DFS(0, 0, false);
        sb.append(sum);

        //System.out.println(sb.toString().trim());
        writer.println(sb.toString().trim());
        writer.flush();
        in.close();
    }

    static void sort(int[] a) {
        Random rand = new Random();
        for (int i = a.length - 1; i > 0; i--) {
            int index = rand.nextInt(i + 1);
            // Simple swap
            int temp = a[index];
            a[index] = a[i];
            a[i] = temp;
        }
        Arrays.sort(a);
    }

    private static void DFS(int vertex, int con, boolean b) {
        if (visited[vertex]) {
            return;
        }
        visited[vertex] = true;
        if (cats[vertex]) {
            con++;
        }
        if (con > m) {
            //b = true;
            return;
        }
        if (!cats[vertex]) {
            con = 0;
        }
        if (graph[vertex].size() == 1 && !b) {
            sum++;
        }
        for (Edge e : graph[vertex]) {
            DFS(e.to, con, b);
        }
    }
}

class Edge {

    int from, to;

    public Edge(int from, int to) {
        this.from = from;
        this.to = to;
    }
}

class MyScanner {

    BufferedReader reader;
    StringTokenizer tokenizer;

    public MyScanner(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.awt.Point;
import java.io.BufferedOutputStream;
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.lang.reflect.Array;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.PriorityQueue;
import java.util.Random;
import java.util.StringTokenizer;
import static java.lang.Math.*;

/**
 *
 * @author Mojtaba
 */
public class Main {

    static int n, m;
    static boolean[] cats;
    static boolean[] visited;
    static long sum;
    static ArrayList<Edge>[] graph;

    public static void main(String[] args) throws IOException {
        MyScanner in = new MyScanner(System.in);
        PrintWriter writer = new PrintWriter(new BufferedOutputStream(System.out));
        StringBuilder sb = new StringBuilder("");

        n = in.nextInt();
        m = in.nextInt();
        cats = new boolean[n];
        graph = new ArrayList[n];
        visited = new boolean[n];
        for (int i = 0; i < n; i++) {
            graph[i] = new ArrayList<>();
        }
        for (int i = 0; i < n; i++) {
            cats[i] = in.nextInt() == 1;
        }
        for (int i = 1; i < n; i++) {
            int from = in.nextInt() - 1;
            int to = in.nextInt() - 1;
            graph[from].add(new Edge(from, to));
        }
        DFS(0, 0, false);
        sb.append(sum);

        //System.out.println(sb.toString().trim());
        writer.println(sb.toString().trim());
        writer.flush();
        in.close();
    }

    static void sort(int[] a) {
        Random rand = new Random();
        for (int i = a.length - 1; i > 0; i--) {
            int index = rand.nextInt(i + 1);
            // Simple swap
            int temp = a[index];
            a[index] = a[i];
            a[i] = temp;
        }
        Arrays.sort(a);
    }

    private static void DFS(int vertex, int con, boolean b) {
        if (visited[vertex]) {
            return;
        }
        visited[vertex] = true;
        if (cats[vertex]) {
            con++;
        }
        if (con > m) {
            //b = true;
            return;
        }
        if (!cats[vertex]) {
            con = 0;
        }
        if (graph[vertex].isEmpty() && !b && vertex != 0) {
            sum++;
        }
        for (Edge e : graph[vertex]) {
            DFS(e.to, con, b);
        }
    }
}

class Edge {

    int from, to;

    public Edge(int from, int to) {
        this.from = from;
        this.to = to;
    }
}

class MyScanner {

    BufferedReader reader;
    StringTokenizer tokenizer;

    public MyScanner(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.util.Arrays;
import java.util.LinkedList;
import java.util.Scanner;

public class Main {

	public static int K = 0;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		boolean cats[] = new boolean[n];
		LinkedList<Integer>[] ll = new LinkedList[n];
		for(int i = 0; i < n; i++){
			ll[i] = new LinkedList<Integer>();
		}
		for(int i = 0; i < n; i++){
			int c = sc.nextInt();
			if(c == 0){
				cats[i] = false;
			}else{
				cats[i] =true;
			}
		}
		for(int i = 0; i< n-1; i++){
			int a = sc.nextInt();
			int b = sc.nextInt();
			ll[a-1].add(b-1);
			ll[b-1].add(a-1);
		}
		boolean bb[] = new boolean[n];
		Arrays.fill(bb, false);
		BFS(ll, bb, cats, 0, 0, m);
		System.out.println(K);

	}

	public static void BFS(LinkedList<Integer>[] ll, boolean visited[], boolean cats[], int Ncats, int pos, int max){
		if(cats[pos]){
			Ncats ++;
		}else{
			Ncats = 0;
		}
		visited[pos] = true;
		if(Ncats <= max){
				int s = 0;
				for(Integer i : ll[pos]){
					if(!visited[i]){
						s++;
						BFS(ll, visited, cats, Ncats, i, max);
					}
				}
				if(s == 0){
					K++;
				}

		}
	}

}


import java.util.*;
public class C {
	public static void main(String[] args)
	{
		Scanner in = new Scanner(System.in);
		n = in.nextInt();
		m = in.nextInt();
		adj = new ArrayList[n];
		for(int i = 0; i < n; i ++)
			adj[i] = new ArrayList<Integer>();
		cats = new boolean[n];
		for(int i = 0; i < n; i ++)
			cats[i] = in.nextInt() == 1;
		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);
		}
		System.out.println(go(0, 0, 0));
	}
	static ArrayList<Integer>[] adj;
	static int n;
	static int m;
	static boolean[] cats;
	static int go(int prev, int c, int at)
	{

		if(cats[at])
			c++;

		else
			c = 0;

//		System.out.println(at +" " + prev + " " + c);

		if(c > m)
		{
//			System.out.println(at + " " + c);
			return 0;
		}

//		System.out.println(at + " " + prev + " " + c);

		if(adj[at].size() <= 1)
		{
//			System.out.println("!");
			return 1;
		}

		int ans = 0;
		for(int e: adj[at])
		{
			if(e == prev)
				continue;
			ans += go(at, c, e);
		}
		return ans;
	}
}


import java.util.*;
public class C {
	public static void main(String[] args)
	{
		Scanner in = new Scanner(System.in);
		n = in.nextInt();
		m = in.nextInt();
		adj = new ArrayList[n];
		for(int i = 0; i < n; i ++)
			adj[i] = new ArrayList<Integer>();
		cats = new boolean[n];
		for(int i = 0; i < n; i ++)
			cats[i] = in.nextInt() == 1;
		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);
		}
		adj[0].add(0);
		System.out.println(go(0, 0, 0));
	}
	static ArrayList<Integer>[] adj;
	static int n;
	static int m;
	static boolean[] cats;
	static int go(int prev, int c, int at)
	{

		if(cats[at])
			c++;

		else
			c = 0;

//		System.out.println(at +" " + prev + " " + c);

		if(c > m)
		{
//			System.out.println(at + " " + c);
			return 0;
		}

//		System.out.println(at + " " + prev + " " + c);

		if(adj[at].size() == 1)
		{
//			System.out.println("!");
			return 1;
		}

		int ans = 0;
		for(int e: adj[at])
		{
			if(e == prev)
				continue;
			ans += go(at, c, e);
		}
		return ans;
	}
}


import java.util.*;
public class C {
	public static void main(String[] args)
	{
		Scanner in = new Scanner(System.in);
		n = in.nextInt();
		m = in.nextInt();
		adj = new ArrayList[n];
		for(int i = 0; i < n; i ++)
			adj[i] = new ArrayList<Integer>();
		cats = new boolean[n];
		for(int i = 0; i < n; i ++)
			cats[i] = in.nextInt() == 1;
		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);
		}
		System.out.println(go(0, 0, 0));
	}
	static ArrayList<Integer>[] adj;
	static int n;
	static int m;
	static boolean[] cats;
	static int go(int prev, int c, int at)
	{

		if(cats[at])
			c++;

		else
			c = 0;

		if(c > m)
		{
//			System.out.println(at + " " + c);
			return 0;
		}

//		System.out.println(at + " " + prev + " " + c);

		if(adj[at].size() == 1)
		{
			return 1;
		}

		int ans = 0;
		for(int e: adj[at])
		{
			if(e == prev)
				continue;
			ans += go(at, c, e);
		}
		return ans;
	}
}


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.StringTokenizer;

public class Main {

    static class TNode
    {
        int data;
        TNode parent;
        ArrayList<TNode> children;
        public TNode(int data)
        {
            this.data = data;
            children = new ArrayList<>();
            parent=null;
        }
    }

    public static void main(String[] args) throws IOException {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        BufferedWriter out = new BufferedWriter(new OutputStreamWriter(
                outputStream, "ASCII"));
        CustomScanner sc = new CustomScanner(inputStream);
        solve(sc, out);
        out.flush();
        out.close();
    }

    static int totalPaths = 0;

    static void solve(CustomScanner sc, BufferedWriter out) throws IOException {
        int n = sc.nextInt(), m = sc.nextInt();
        ArrayList<TNode> list = new ArrayList<>(100001);
        for (int i=0; i<n; i++)
        {
            int cat = sc.nextInt();
            TNode node = new TNode(cat);
            list.add(node);
        }
        for (int i=1; i<=n-1; i++)
        {
            int x = sc.nextInt()-1, y = sc.nextInt()-1;
            TNode parent = list.get(x);
            TNode child = list.get(y);
            child.parent = parent;
            parent.children.add(child);
        }
        TNode node = list.get(0);
        while(node.parent!=null)
            node=node.parent;
        TNode root = node;
        getGoodPaths(root,m,0);
        out.write(Integer.toString(totalPaths));
        out.newLine();
    }

    static void getGoodPaths(TNode node, int m, int consecutiveCatsSoFar)
    {
        if (node.children.size()==0)
        {
            if (consecutiveCatsSoFar<m)
                totalPaths++;
            else if (consecutiveCatsSoFar<=m && node.data==0)
                    totalPaths++;
            return;
        }
        if (node.data==1 && consecutiveCatsSoFar==m)
            return;
        for (TNode child: node.children)
        {
            int cats = consecutiveCatsSoFar;
            if (node.data==0)
                cats=0;
            else
                cats++;
            getGoodPaths(child, m, cats);
        }
    }

    static class CustomScanner {
        BufferedReader br;
        StringTokenizer st;

        public CustomScanner(InputStream stream) {
            br = new BufferedReader(new InputStreamReader(stream));
        }

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

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

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

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

        public String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.StringTokenizer;

public class Main {

    static class Graph
    {
        ArrayList<Vertex> vertex;
        public Graph()
        {
            vertex = new ArrayList<>();
        }

        public Graph(int vertexCount)
        {
            vertex = new ArrayList<>();
            for (int i=0; i<vertexCount; i++)
                vertex.add(new Vertex(0));
        }

        public void addEdge (int source, int destination, int weight)
        {
            vertex.get(source).edges.add(new Edge(destination, weight));
        }
    }

    static class Vertex
    {
        ArrayList<Edge> edges; int data;
        public Vertex (int data)
        {
            this.data = data;
            edges = new ArrayList<>();
        }
    }

    static class Edge
    {
        int destination, weight;
        public Edge (int destination, int weight)
        {
            this.destination = destination;
            this.weight = weight;
        }
    }

    public static void main(String[] args) throws IOException {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        BufferedWriter out = new BufferedWriter(new OutputStreamWriter(
                outputStream, "ASCII"));
        CustomScanner sc = new CustomScanner(inputStream);
        solve(sc, out);
        out.flush();
        out.close();
    }

    static void solve(CustomScanner sc, BufferedWriter out) throws IOException {
        int n = sc.nextInt(), m = sc.nextInt();
        Graph g = new Graph(n);
        for (int i=0; i<n; i++)
        {
            int a = sc.nextInt();
            g.vertex.get(i).data = a;
        }
        for (int i=1; i<=n-1; i++)
        {
            int x= sc.nextInt()-1, y =sc.nextInt()-1;
            g.addEdge(x, y, 0);
            g.addEdge(y, x, 0);
        }
        boolean[] visited = new boolean[n];
        getPossiblePaths(g, 0, visited, m, 0);
        out.write(Integer.toString(totalPaths));
        out.newLine();
    }

    static int totalPaths = 0;

    static void getPossiblePaths(Graph g, int v, boolean[] visited, int m, int consecutiveCats)
    {
        Vertex curr = g.vertex.get(v);
        visited[v] = true;
        if (consecutiveCats==m && curr.data==1)
            return;
        if (curr.edges.size()==1)
        {
            totalPaths++;
            return;
        }
        int cats = (curr.data==0)?0:consecutiveCats+1;
        for (Edge e: curr.edges)
        {
            if (!visited[e.destination])
                getPossiblePaths(g, e.destination, visited, m, cats);
        }
    }

    static class CustomScanner {
        BufferedReader br;
        StringTokenizer st;

        public CustomScanner(InputStream stream) {
            br = new BufferedReader(new InputStreamReader(stream));
        }

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

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

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

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

        public String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.StringTokenizer;

public class Main {

    static class TNode {
        int data;
        TNode parent;
        ArrayList<TNode> children;

        public TNode(int data) {
            this.data = data;
            children = new ArrayList<>();
            parent = null;
        }
    }

    public static void main(String[] args) throws IOException {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        BufferedWriter out = new BufferedWriter(new OutputStreamWriter(
                outputStream, "ASCII"));
        CustomScanner sc = new CustomScanner(inputStream);
        solve(sc, out);
        out.flush();
        out.close();
    }

    static int totalPaths = 0;

    static void solve(CustomScanner sc, BufferedWriter out) throws IOException {
        int n = sc.nextInt(), m = sc.nextInt();
        ArrayList<TNode> list = new ArrayList<>(100001);
        for (int i = 0; i < n; i++) {
            int cat = sc.nextInt();
            TNode node = new TNode(cat);
            list.add(node);
        }
        for (int i = 1; i <= n - 1; i++) {
            int x = sc.nextInt() - 1, y = sc.nextInt() - 1;
            TNode parent = list.get(x);
            TNode child = list.get(y);
            child.parent = parent;
            parent.children.add(child);
        }
        TNode node = list.get(0);
        while (node.parent != null)
            node = node.parent;
        TNode root = node;
        getGoodPaths(root, m, 0);
        out.write(Integer.toString(totalPaths));
        out.newLine();
    }

    static void getGoodPaths(TNode node, int m, int consecutiveCatsSoFar) {
        if (consecutiveCatsSoFar>m)
            return;
        if (node.children.size() == 0) {
            if (consecutiveCatsSoFar < m)
                totalPaths++;
            else if (consecutiveCatsSoFar == m && node.data == 0)
                totalPaths++;
            return;
        }
        if (node.data == 1 && consecutiveCatsSoFar >= m)
            return;
        for (TNode child : node.children) {
            int cats = consecutiveCatsSoFar;
            if (node.data == 0)
                cats = 0;
            else
                cats++;
            getGoodPaths(child, m, cats);
        }
    }

    static class CustomScanner {
        BufferedReader br;
        StringTokenizer st;

        public CustomScanner(InputStream stream) {
            br = new BufferedReader(new InputStreamReader(stream));
        }

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

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

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

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

        public String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.StringTokenizer;

public class Main {

    static class TNode
    {
        int data;
        TNode parent;
        ArrayList<TNode> children;
        public TNode(int data)
        {
            this.data = data;
            children = new ArrayList<>();
            parent=null;
        }
    }

    public static void main(String[] args) throws IOException {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        BufferedWriter out = new BufferedWriter(new OutputStreamWriter(
                outputStream, "ASCII"));
        CustomScanner sc = new CustomScanner(inputStream);
        solve(sc, out);
        out.flush();
        out.close();
    }

    static int totalPaths = 0;

    static void solve(CustomScanner sc, BufferedWriter out) throws IOException {
        int n = sc.nextInt(), m = sc.nextInt();
        ArrayList<TNode> list = new ArrayList<>(100000);
        for (int i=0; i<n; i++)
        {
            int cat = sc.nextInt();
            TNode node = new TNode(cat);
            list.add(node);
        }
        for (int i=1; i<=n-1; i++)
        {
            int x = sc.nextInt()-1, y = sc.nextInt()-1;
            TNode parent = list.get(x);
            TNode child = list.get(y);
            child.parent = parent;
            parent.children.add(child);
        }
        TNode node = list.get(0);
        while(node.parent!=null)
            node=node.parent;
        TNode root = node;
        getGoodPaths(root,m,0);
        out.write(Integer.toString(totalPaths));
        out.newLine();
    }

    static void getGoodPaths(TNode node, int m, int consecutiveCatsSoFar)
    {
        if (node.children.size()==0)
        {
            if (consecutiveCatsSoFar<m)
                totalPaths++;
            else if (consecutiveCatsSoFar<=m && node.data==0)
                    totalPaths++;
            return;
        }
        if (node.data==1 && consecutiveCatsSoFar==m)
            return;
        for (TNode child: node.children)
        {
            int cats = consecutiveCatsSoFar;
            if (node.data==0)
                cats=0;
            else
                cats++;
            getGoodPaths(child, m, cats);
        }
    }

    static class CustomScanner {
        BufferedReader br;
        StringTokenizer st;

        public CustomScanner(InputStream stream) {
            br = new BufferedReader(new InputStreamReader(stream));
        }

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

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

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

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

        public String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.StringTokenizer;

public class Main {

    static class Graph
    {
        ArrayList<Vertex> vertex;
        public Graph()
        {
            vertex = new ArrayList<>();
        }

        public Graph(int vertexCount)
        {
            vertex = new ArrayList<>();
            for (int i=0; i<vertexCount; i++)
                vertex.add(new Vertex(0));
        }

        public void addEdge (int source, int destination, int weight)
        {
            vertex.get(source).edges.add(new Edge(destination, weight));
        }
    }

    static class Vertex
    {
        ArrayList<Edge> edges; int data;
        public Vertex (int data)
        {
            this.data = data;
            edges = new ArrayList<>();
        }
    }

    static class Edge
    {
        int destination, weight;
        public Edge (int destination, int weight)
        {
            this.destination = destination;
            this.weight = weight;
        }
    }

    public static void main(String[] args) throws IOException {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        BufferedWriter out = new BufferedWriter(new OutputStreamWriter(
                outputStream, "ASCII"));
        CustomScanner sc = new CustomScanner(inputStream);
        solve(sc, out);
        out.flush();
        out.close();
    }

    static void solve(CustomScanner sc, BufferedWriter out) throws IOException {
        int n = sc.nextInt(), m = sc.nextInt();
        Graph g = new Graph(n);
        for (int i=0; i<n; i++)
        {
            int a = sc.nextInt();
            g.vertex.get(i).data = a;
        }
        for (int i=1; i<=n-1; i++)
        {
            int x= sc.nextInt()-1, y =sc.nextInt()-1;
            g.addEdge(x, y, 0);
            g.addEdge(y, x, 0);
        }
        boolean[] visited = new boolean[n];
        getPossiblePaths(g, 0, visited, m, 0);
        out.write(Integer.toString(totalPaths));
        out.newLine();
    }

    static int totalPaths = 0;

    static void getPossiblePaths(Graph g, int v, boolean[] visited, int m, int consecutiveCats)
    {
        Vertex curr = g.vertex.get(v);
        visited[v] = true;
        if (consecutiveCats==m && curr.data==1)
            return;
        if (curr.edges.size()==1 && v>0)
        {
            totalPaths++;
            return;
        }
        int cats = (curr.data==0)?0:consecutiveCats+1;
        for (Edge e: curr.edges)
        {
            if (!visited[e.destination])
                getPossiblePaths(g, e.destination, visited, m, cats);
        }
    }

    static class CustomScanner {
        BufferedReader br;
        StringTokenizer st;

        public CustomScanner(InputStream stream) {
            br = new BufferedReader(new InputStreamReader(stream));
        }

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

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

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

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

        public String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}


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

public class c2 {
	BufferedReader br;
	StringTokenizer in;
	PrintWriter out;

	public String nextToken() throws IOException {
		while (in == null || !in.hasMoreTokens()) {
			in = new StringTokenizer(br.readLine());
		}
		return in.nextToken();
	}

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

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

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

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

	static int cat[];
	static ArrayList<Integer> edges[];
	static int ans;
	static boolean was[];
	static int m;

	static void dfs(int cur, int cnt, boolean w) {
		boolean fl  = w;

		if (cnt > m){
			fl = true;
		}

		int deg = 0;
		was[cur] = true;

		for (int i : edges[cur]) {
			if (!was[i]) {
				if (cat[i] == 1) {
					dfs(i, cnt + 1, fl);
				} else {
					dfs(i, 0, fl);
				}
				deg++;
			}
		}

		if (deg == 0 && cnt <= m && !fl) {
			ans++;
		}
	}

	public void solve() throws IOException {
		int n = nextInt();
		m = nextInt();

		edges = new ArrayList[n];
		cat = new int[n];
		was = new boolean[n];

		for (int i = 0; i < n; i++) {
			cat[i] = nextInt();
			was[i] = false;
		}

		for (int i = 0; i < n; i++) {
			edges[i] = new ArrayList<Integer>();
		}

		for (int i = 0; i < n - 1; i++) {
			int x = nextInt() - 1;
			int y = nextInt() - 1;

			edges[x].add(y);
			edges[y].add(x);
		}

		ans = 0;

		if (cat[0] == 1) {
			dfs(0, 1, false);
		} else {
			dfs(0, 0, false);
		}

		out.println(ans);
	}

	public void run() {
		try {
			br = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);
			solve();
			out.close();
		} catch (IOException e) {
			e.printStackTrace();
			System.exit(1);
		}
	}
}