import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.lang.Character.Subset;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Random;
import java.util.StringTokenizer;
import java.util.TreeMap;

import javax.management.RuntimeErrorException;

public class Codeforces {

    StringTokenizer tok;
    BufferedReader in;
    PrintWriter out;

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

    void init() {
        try {
            if (OJ) {
                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");
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    String readString() {
        try {
            while (tok == null || !tok.hasMoreTokens()) {
                tok = new StringTokenizer(in.readLine());
            }
            return tok.nextToken();
        } catch (Throwable t) {
            throw new RuntimeException(t);
        }
    }

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

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

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

    void run() {
        init();
        long time = System.currentTimeMillis();
        solve();
        System.err.println(System.currentTimeMillis() - time);
        out.close();
    }

    class Friend implements Comparable<Friend> {
        int a;
        int b;

        public Friend(int a, int b) {
            super();
            this.a = a;
            this.b = b;
        }

        @Override
        public int compareTo(Friend arg0) {
            return a - arg0.a;
        }

    }

    ArrayList<Integer>[] graph;
    int[] cat;
    int m;

    int ans;
    void dfs(int x, int cnt, int p) {
        if (cat[x] == 1) {
            cnt++;
        } else {
            cnt = 0;
        }
        if (cnt > m) return;
        if (graph[x].size() == 1) {
            ans++;
            return;
        }
        for (int y : graph[x]) {
            if (y != p)
                dfs(y, cnt, x);
        }

    }

    void solve() {
        int n = readInt();
        m = readInt();
        graph = new ArrayList[n];
        for (int i=0;i<n;i++) graph[i] = new ArrayList<Integer>();

        cat = new int[n];
        for (int i=0;i<n;i++) {
            cat[i] = readInt();
        }

        for (int i=0;i<n - 1;i++) {
            int a = readInt()-1;
            int b = readInt()-1;
            graph[a].add(b);
            graph[b].add(a);
        }

        dfs(0,0,-1);
        out.println(ans);

    }

}


import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.lang.Character.Subset;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Random;
import java.util.StringTokenizer;
import java.util.TreeMap;

import javax.management.RuntimeErrorException;

public class Codeforces {

    StringTokenizer tok;
    BufferedReader in;
    PrintWriter out;

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

    void init() {
        try {
            if (OJ) {
                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");
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    String readString() {
        try {
            while (tok == null || !tok.hasMoreTokens()) {
                tok = new StringTokenizer(in.readLine());
            }
            return tok.nextToken();
        } catch (Throwable t) {
            throw new RuntimeException(t);
        }
    }

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

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

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

    void run() {
        init();
        long time = System.currentTimeMillis();
        solve();
        System.err.println(System.currentTimeMillis() - time);
        out.close();
    }

    class Friend implements Comparable<Friend> {
        int a;
        int b;

        public Friend(int a, int b) {
            super();
            this.a = a;
            this.b = b;
        }

        @Override
        public int compareTo(Friend arg0) {
            return a - arg0.a;
        }

    }

    ArrayList<Integer>[] graph;
    int[] cat;
    int m;

    int ans;
    void dfs(int x, int cnt, int p) {
        if (cat[x] == 1) {
            cnt++;
        } else {
            cnt = 0;
        }
        if (cnt > m) return;
        if (graph[x].size() == 1 && p != -1) {
            ans++;
            return;
        }
        for (int y : graph[x]) {
            if (y != p)
                dfs(y, cnt, x);
        }

    }

    void solve() {
        int n = readInt();
        m = readInt();
        graph = new ArrayList[n];
        for (int i=0;i<n;i++) graph[i] = new ArrayList<Integer>();

        cat = new int[n];
        for (int i=0;i<n;i++) {
            cat[i] = readInt();
        }

        for (int i=0;i<n - 1;i++) {
            int a = readInt()-1;
            int b = readInt()-1;
            graph[a].add(b);
            graph[b].add(a);
        }

        dfs(0,0,-1);
        out.println(ans);

    }

}


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

/**
 * Created by smalex on 22/09/15.
 */
public class P580C {
  static BufferedReader in;
  static StringTokenizer tok;

  public static void main(String[] args) throws IOException {
    in = new BufferedReader(new InputStreamReader(System.in));
    int n = nextInt();
    int m = nextInt();
    int[] cats = nextIntArray(n, 0);
    Map<Integer, List<Integer>> connected = new HashMap<>();
    for (int i = 1; i < n; i++) {
      int a = nextInt();
      int b = nextInt();
      connectVertex(connected, a, b);
      connectVertex(connected, b, a);
    }
    int[] costs = new int[n + 1];
    Arrays.fill(costs, Integer.MAX_VALUE);

    costs[1] = cats[0];
    LinkedList<Integer> q = new LinkedList<>();
    q.add(1);
    boolean[] visited = new boolean[n + 1];
    boolean[] isLeaf = new boolean[n + 1];
    Arrays.fill(isLeaf, true);
    visited[1] = true;
    while (!q.isEmpty()) {
      Integer pop = q.pop();
      int cost = costs[pop];
      List<Integer> vertexes = connected.get(pop);
      if (vertexes != null) {
        for (Integer vertex : vertexes) {
          int cat = cats[vertex - 1];
          if (!visited[vertex]) {
            visited[vertex] = true;
            isLeaf[pop] = false;
            costs[vertex] = Math.min(newCost(cost, cat), costs[vertex]);
            if (costs[vertex] <= m) {
              q.add(vertex);
            }
          }
        }
      }
    }
//     System.out.println("costs = " + Arrays.toString(costs));
//     System.out.println("isLeaf = " + Arrays.toString(isLeaf));
    int res = 0;
    for (int i = 2; i < costs.length; i++) {
      if (costs[i] <= m && isLeaf[i]) {
        res++;
      }
    }
    System.out.println(res);
  }

  private static int newCost(int cost, int cat) {
    return cat == 0 ? 0 : cost + cat;
  }

  private static void connectVertex(Map<Integer, List<Integer>> connected, int a, int b) {
    List<Integer> values = connected.get(a);
    if (values == null) {
      values = new ArrayList<>();
      connected.put(a, values);
    }
    values.add(b);
  }

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

  static int[] nextIntArray(int len, int start) throws IOException {
    int[] a = new int[len];
    for (int i = start; i < len; i++)
      a[i] = nextInt();
    return a;
  }

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

  static long[] nextLongArray(int len, int start) throws IOException {
    long[] a = new long[len];
    for (int i = start; i < len; i++)
      a[i] = nextLong();
    return a;
  }

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


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

/**
 * Created by smalex on 22/09/15.
 */
public class P580C {
  static BufferedReader in;
  static StringTokenizer tok;

  public static void main(String[] args) throws IOException {
    in = new BufferedReader(new InputStreamReader(System.in));
    int n = nextInt();
    int m = nextInt();
    int[] cats = nextIntArray(n, 0);
    Map<Integer, List<Integer>> connected = new HashMap<>();
    for (int i = 1; i < n; i++) {
      int a = nextInt();
      int b = nextInt();
      connectVertex(connected, a, b);
      connectVertex(connected, b, a);
    }
    int[] costs = new int[n + 1];
    Arrays.fill(costs, Integer.MAX_VALUE);

    costs[1] = cats[0];
    LinkedList<Integer> q = new LinkedList<>();
    q.add(1);
    boolean[] visited = new boolean[n + 1];
    boolean[] isLeaf = new boolean[n + 1];
    Arrays.fill(isLeaf, true);
    while (!q.isEmpty()) {
      Integer pop = q.pop();
      int cost = costs[pop];
      List<Integer> vertexes = connected.get(pop);
      if (vertexes != null) {
        for (Integer vertex : vertexes) {
          int cat = cats[vertex - 1];
          if (!visited[vertex] || newCost(cost, cat) < costs[vertex]) {
            visited[vertex] = true;
            isLeaf[pop] = false;
            costs[vertex] = Math.min(newCost(cost, cat), costs[vertex]);
            if (costs[vertex] <= m) {
              q.add(vertex);
            }
          }
        }
      }
    }
    // System.out.println("costs = " + Arrays.toString(costs));
    int res = 0;
    for (int i = 2; i < costs.length; i++) {
      if (costs[i] <= m && isLeaf[i]) {
        res++;
      }
    }
    System.out.println(res);
  }

  private static int newCost(int cost, int cat) {
    return cat == 0 ? 0 : cost + cat;
  }

  private static void connectVertex(Map<Integer, List<Integer>> connected, int a, int b) {
    List<Integer> values = connected.get(a);
    if (values == null) {
      values = new ArrayList<>();
      connected.put(a, values);
    }
    values.add(b);
  }

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

  static int[] nextIntArray(int len, int start) throws IOException {
    int[] a = new int[len];
    for (int i = start; i < len; i++)
      a[i] = nextInt();
    return a;
  }

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

  static long[] nextLongArray(int len, int start) throws IOException {
    long[] a = new long[len];
    for (int i = start; i < len; i++)
      a[i] = nextLong();
    return a;
  }

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


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

/**
 * Created by smalex on 22/09/15.
 */
public class P580C {
  static BufferedReader in;
  static StringTokenizer tok;

  public static void main(String[] args) throws IOException {
    in = new BufferedReader(new InputStreamReader(System.in));
    int n = nextInt();
    int m = nextInt();
    int[] cats = nextIntArray(n, 0);
    Map<Integer, List<Integer>> connected = new HashMap<>();
    for (int i = 1; i < n; i++) {
      int a = nextInt();
      int b = nextInt();
      connectVertex(connected, a, b);
      connectVertex(connected, b, a);
    }
    int[] costs = new int[n + 1];
    Arrays.fill(costs, Integer.MAX_VALUE);

    costs[1] = cats[0];
    LinkedList<Integer> q = new LinkedList<>();
    q.add(1);
    boolean[] visited = new boolean[n + 1];
    boolean[] isLeaf = new boolean[n + 1];
    Arrays.fill(isLeaf, true);
    visited[1] = true;
    while (!q.isEmpty()) {
      Integer pop = q.pop();
      int cost = costs[pop];
      List<Integer> vertexes = connected.get(pop);
      if (vertexes != null) {
        for (Integer vertex : vertexes) {
          int cat = cats[vertex - 1];
          if (!visited[vertex] || newCost(cost, cat) < costs[vertex]) {
            visited[vertex] = true;
            isLeaf[pop] = false;
            costs[vertex] = Math.min(newCost(cost, cat), costs[vertex]);
            if (costs[vertex] <= m) {
              q.add(vertex);
            }
          }
        }
      }
    }
    // System.out.println("costs = " + Arrays.toString(costs));
    // System.out.println("isLeaf = " + Arrays.toString(isLeaf));
    int res = 0;
    for (int i = 2; i < costs.length; i++) {
      if (costs[i] <= m && isLeaf[i]) {
        res++;
      }
    }
    System.out.println(res);
  }

  private static int newCost(int cost, int cat) {
    return cat == 0 ? 0 : cost + cat;
  }

  private static void connectVertex(Map<Integer, List<Integer>> connected, int a, int b) {
    List<Integer> values = connected.get(a);
    if (values == null) {
      values = new ArrayList<>();
      connected.put(a, values);
    }
    values.add(b);
  }

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

  static int[] nextIntArray(int len, int start) throws IOException {
    int[] a = new int[len];
    for (int i = start; i < len; i++)
      a[i] = nextInt();
    return a;
  }

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

  static long[] nextLongArray(int len, int start) throws IOException {
    long[] a = new long[len];
    for (int i = start; i < len; i++)
      a[i] = nextLong();
    return a;
  }

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


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

/**
 * Created by smalex on 22/09/15.
 */
public class P580C {
  static BufferedReader in;
  static StringTokenizer tok;

  public static void main(String[] args) throws IOException {
//    in = new BufferedReader(new InputStreamReader(new FileInputStream("test.io")));
    in = new BufferedReader(new InputStreamReader(System.in));
    int n = nextInt();
    int m = nextInt();
    int[] cats = nextIntArray(n, 0);
    Map<Integer, List<Integer>> connected = new HashMap<>();
    for (int i = 1; i < n; i++) {
      int a = nextInt();
      int b = nextInt();
      connectVertex(connected, a, b);
      connectVertex(connected, b, a);
    }
    int[] cost = new int[n + 1];
    Arrays.fill(cost, Integer.MAX_VALUE);

    cost[1] = cats[0];
    LinkedList<Integer> q = new LinkedList<>();
    q.add(1);
    boolean[] visited = new boolean[n + 1];
    while (!q.isEmpty()) {
      Integer pop = q.pop();
      int currentcost = cost[pop];

      List<Integer> integers = connected.get(pop);
      if (integers != null) {
        for (Integer integer : integers) {
          if (!visited[integer]) {
            q.add(integer);
            visited[integer] = true;
            cost[integer] = Math.min(currentcost + cats[integer - 1], cost[integer]);
          }
        }
      }
    }
    int res = 0;
    for (int i = 2; i < cost.length; i++) {
      int i1 = cost[i];
      if (i1 <= m) {
        res++;
      }
    }
    System.out.println(res);
  }

  private static void connectVertex(Map<Integer, List<Integer>> connected, int a, int b) {
    List<Integer> values = connected.get(a);
    if (values == null) {
      values = new ArrayList<>();
      connected.put(a, values);
    }
    values.add(b);
  }

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

  static int[] nextIntArray(int len, int start) throws IOException {
    int[] a = new int[len];
    for (int i = start; i < len; i++)
      a[i] = nextInt();
    return a;
  }

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

  static long[] nextLongArray(int len, int start) throws IOException {
    long[] a = new long[len];
    for (int i = start; i < len; i++)
      a[i] = nextLong();
    return a;
  }

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


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

/**
 * Created by smalex on 22/09/15.
 */
public class P580C {
  static BufferedReader in;
  static StringTokenizer tok;

  public static void main(String[] args) throws IOException {
    in = new BufferedReader(new InputStreamReader(System.in));
    int n = nextInt();
    int m = nextInt();
    int[] cats = nextIntArray(n, 0);
    Map<Integer, List<Integer>> connected = new HashMap<>();
    for (int i = 1; i < n; i++) {
      int a = nextInt();
      int b = nextInt();
      connectVertex(connected, a, b);
      connectVertex(connected, b, a);
    }
    int[] costs = new int[n + 1];
    Arrays.fill(costs, Integer.MAX_VALUE);

    costs[1] = cats[0];
    LinkedList<Integer> q = new LinkedList<>();
    q.add(1);
    boolean[] visited = new boolean[n + 1];
    while (!q.isEmpty()) {
      Integer pop = q.pop();
      int cost = costs[pop];
      List<Integer> vertexes = connected.get(pop);
      if (vertexes != null) {
        for (Integer vertex : vertexes) {
          int cat = cats[vertex - 1];
          if (!visited[vertex] || newCost(cost, cat) < costs[vertex]) {
            visited[vertex] = true;
            int a = newCost(cost, cat);
            costs[vertex] = Math.min(a, costs[vertex]);
            if (costs[vertex] <= m) {
              q.add(vertex);
            }
          }
        }
      }
    }
    // System.out.println("costs = " + Arrays.toString(costs));
    int res = 0;
    for (int i = 2; i < costs.length; i++) {
      if (costs[i] <= m && connected.get(i).size() == 1) {
        res++;
      }
    }
    System.out.println(res);
  }

  private static int newCost(int cost, int cat) {
    return cat == 0 ? 0 : cost + cat;
  }

  private static void connectVertex(Map<Integer, List<Integer>> connected, int a, int b) {
    List<Integer> values = connected.get(a);
    if (values == null) {
      values = new ArrayList<>();
      connected.put(a, values);
    }
    values.add(b);
  }

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

  static int[] nextIntArray(int len, int start) throws IOException {
    int[] a = new int[len];
    for (int i = start; i < len; i++)
      a[i] = nextInt();
    return a;
  }

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

  static long[] nextLongArray(int len, int start) throws IOException {
    long[] a = new long[len];
    for (int i = start; i < len; i++)
      a[i] = nextLong();
    return a;
  }

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


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

/**
 * Created by smalex on 22/09/15.
 */
public class P580C {
  static BufferedReader in;
  static StringTokenizer tok;

  public static void main(String[] args) throws IOException {
    in = new BufferedReader(new InputStreamReader(System.in));
    int n = nextInt();
    int m = nextInt();
    int[] cats = nextIntArray(n, 0);
    Map<Integer, List<Integer>> connected = new HashMap<>();
    for (int i = 1; i < n; i++) {
      int a = nextInt();
      int b = nextInt();
      connectVertex(connected, a, b);
      connectVertex(connected, b, a);
    }
    int[] costs = new int[n + 1];
    Arrays.fill(costs, Integer.MAX_VALUE);

    costs[1] = cats[0];
    LinkedList<Integer> q = new LinkedList<>();
    q.add(1);
    boolean[] visited = new boolean[n + 1];
    while (!q.isEmpty()) {
      Integer pop = q.pop();
      int cost = costs[pop];
      List<Integer> vertexes = connected.get(pop);
      if (vertexes != null) {
        for (Integer vertex : vertexes) {
          if (!visited[vertex] || cost + cats[vertex - 1] < costs[vertex]) {
            visited[vertex] = true;
            costs[vertex] = Math.min(cost + cats[vertex - 1], costs[vertex]);
            if (costs[vertex] <= m) {
              q.add(vertex);
            }
          }
        }
      }
    }
//    System.out.println("costs = " + Arrays.toString(costs));
    int res = 0;
    for (int i = 2; i < costs.length; i++) {
      if (costs[i] <= m) {
        res++;
      }
    }
    System.out.println(res);
  }

  private static void connectVertex(Map<Integer, List<Integer>> connected, int a, int b) {
    List<Integer> values = connected.get(a);
    if (values == null) {
      values = new ArrayList<>();
      connected.put(a, values);
    }
    values.add(b);
  }

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

  static int[] nextIntArray(int len, int start) throws IOException {
    int[] a = new int[len];
    for (int i = start; i < len; i++)
      a[i] = nextInt();
    return a;
  }

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

  static long[] nextLongArray(int len, int start) throws IOException {
    long[] a = new long[len];
    for (int i = start; i < len; i++)
      a[i] = nextLong();
    return a;
  }

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


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

/**
 * Created by smalex on 22/09/15.
 */
public class P580C {
  static BufferedReader in;
  static StringTokenizer tok;

  public static void main(String[] args) throws IOException {
    in = new BufferedReader(new InputStreamReader(System.in));
    int n = nextInt();
    int m = nextInt();
    int[] cats = nextIntArray(n, 0);
    Map<Integer, List<Integer>> connected = new HashMap<>();
    for (int i = 1; i < n; i++) {
      int a = nextInt();
      int b = nextInt();
      connectVertex(connected, a, b);
      connectVertex(connected, b, a);
    }
    int[] costs = new int[n + 1];
    Arrays.fill(costs, Integer.MAX_VALUE);

    costs[1] = cats[0];
    LinkedList<Integer> q = new LinkedList<>();
    q.add(1);
    boolean[] visited = new boolean[n + 1];
    while (!q.isEmpty()) {
      Integer pop = q.pop();
      int cost = costs[pop];
      List<Integer> vertexes = connected.get(pop);
      if (vertexes != null) {
        for (Integer vertex : vertexes) {
          if (!visited[vertex] || cost + cats[vertex - 1] < costs[vertex]) {
            visited[vertex] = true;
            int a = cats[vertex - 1] == 0 ? 0 : cost + cats[vertex - 1];
            costs[vertex] = Math.min(a, costs[vertex]);
            if (costs[vertex] <= m) {
              q.add(vertex);
            }
          }
        }
      }
    }
    // System.out.println("costs = " + Arrays.toString(costs));
    int res = 0;
    for (int i = 2; i < costs.length; i++) {
      if (costs[i] <= m && connected.get(i).size() == 1) {
        res++;
      }
    }
    System.out.println(res);
  }

  private static void connectVertex(Map<Integer, List<Integer>> connected, int a, int b) {
    List<Integer> values = connected.get(a);
    if (values == null) {
      values = new ArrayList<>();
      connected.put(a, values);
    }
    values.add(b);
  }

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

  static int[] nextIntArray(int len, int start) throws IOException {
    int[] a = new int[len];
    for (int i = start; i < len; i++)
      a[i] = nextInt();
    return a;
  }

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

  static long[] nextLongArray(int len, int start) throws IOException {
    long[] a = new long[len];
    for (int i = start; i < len; i++)
      a[i] = nextLong();
    return a;
  }

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


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

/**
 * Created by smalex on 22/09/15.
 */
public class P580C {
  static BufferedReader in;
  static StringTokenizer tok;

  public static void main(String[] args) throws IOException {
    in = new BufferedReader(new InputStreamReader(System.in));
    int n = nextInt();
    int m = nextInt();
    int[] cats = nextIntArray(n, 0);
    Map<Integer, List<Integer>> connected = new HashMap<>();
    for (int i = 1; i < n; i++) {
      int a = nextInt();
      int b = nextInt();
      connectVertex(connected, a, b);
      connectVertex(connected, b, a);
    }
    int[] costs = new int[n + 1];
    Arrays.fill(costs, Integer.MAX_VALUE);

    costs[1] = cats[0];
    LinkedList<Integer> q = new LinkedList<>();
    q.add(1);
    boolean[] visited = new boolean[n + 1];
    while (!q.isEmpty()) {
      Integer pop = q.pop();
      int cost = costs[pop];
      List<Integer> vertexes = connected.get(pop);
      if (vertexes != null) {
        for (Integer vertex : vertexes) {
          int cat = cats[vertex - 1];
          if (!visited[vertex] || newCost(cost, cat) < costs[vertex]) {
            visited[vertex] = true;
            costs[vertex] = Math.min(newCost(cost, cat), costs[vertex]);
            q.add(vertex);
          }
        }
      }
    }
    // System.out.println("costs = " + Arrays.toString(costs));
    int res = 0;
    for (int i = 2; i < costs.length; i++) {
      if (costs[i] <= m && connected.get(i).size() == 1) {
        res++;
      }
    }
    System.out.println(res);
  }

  private static int newCost(int cost, int cat) {
    return cat == 0 ? 0 : cost + cat;
  }

  private static void connectVertex(Map<Integer, List<Integer>> connected, int a, int b) {
    List<Integer> values = connected.get(a);
    if (values == null) {
      values = new ArrayList<>();
      connected.put(a, values);
    }
    values.add(b);
  }

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

  static int[] nextIntArray(int len, int start) throws IOException {
    int[] a = new int[len];
    for (int i = start; i < len; i++)
      a[i] = nextInt();
    return a;
  }

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

  static long[] nextLongArray(int len, int start) throws IOException {
    long[] a = new long[len];
    for (int i = start; i < len; i++)
      a[i] = nextLong();
    return a;
  }

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


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.*;
import java.util.Map.Entry;

public class Main {

    public static PrintWriter out;

    public static void main(String args[]) {

        MyScanner in = new MyScanner();
        int n = in.nextInt();
        int m = in.nextInt();
        int[] presenOfCat = new int[n + 1];
        for (int i = 1; i <= n; i++) {
            presenOfCat[i] = in.nextInt();
        }

        int[] visited = new int[n + 1];
        Map<Integer, List> edges = new TreeMap<Integer, List>();
        List<Boolean> visitedEdge = new ArrayList<>();
        for (int i = 0; i < n - 1; i++) {
            int sourceEdge = in.nextInt();
            int destinationEdge = in.nextInt();
            if (sourceEdge > destinationEdge) {
                int temp = sourceEdge;
                sourceEdge = destinationEdge;
                destinationEdge = temp;
            }
            if (!edges.containsKey(sourceEdge)) {
                List<Integer> list = new ArrayList<>();
                list.add(destinationEdge);
                edges.put(sourceEdge, list);
            } else {
                List<Integer> list = edges.get(sourceEdge);
                list.add(destinationEdge);
                edges.put(sourceEdge, list);
            }

        }

        int current = 0;
        if (presenOfCat[1] == 1) {
            current++;
        }

        System.out.println(getRestaurent(edges, presenOfCat, current, 1, m));
    }

    private static long getRestaurent(Map<Integer, List> edges, int[] presenOfCat, int current, int root, int m) {

        if (!edges.containsKey(root))
            return 1;

        List<Integer> connectedVertices = edges.get(root);
        long count = 0;
        for (int i = 0; i < connectedVertices.size(); i++) {
            int localCurrent = current;
            if (presenOfCat[connectedVertices.get(i)] == 1) {
                localCurrent++;
            } else
                localCurrent = 0;
            if (localCurrent <= m)
                count += getRestaurent(edges, presenOfCat, localCurrent, connectedVertices.get(i), m);
        }

        return count;

    }

    public static class MyScanner {

        BufferedReader br;
        StringTokenizer st;

        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

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

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

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

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

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

    }

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.*;
import java.util.Map.Entry;

public class Main {

    public static PrintWriter out;

    public static void main(String args[]) {

        MyScanner in = new MyScanner();
        int n = in.nextInt();
        int m = in.nextInt();
        int[] presenOfCat = new int[n + 1];
        for (int i = 1; i <= n; i++) {
            presenOfCat[i] = in.nextInt();
        }

        int[] visited = new int[n + 1];
        Map<Integer, List> edges = new TreeMap<Integer, List>();
        List<Boolean> visitedEdge = new ArrayList<>();
        for (int i = 0; i < n - 1; i++) {
            int sourceEdge = in.nextInt();
            int destinationEdge = in.nextInt();

            if (!edges.containsKey(sourceEdge)) {
                List<Integer> list = new ArrayList<>();
                list.add(destinationEdge);
                edges.put(sourceEdge, list);
            } else {
                List<Integer> list = edges.get(sourceEdge);
                list.add(destinationEdge);
                edges.put(sourceEdge, list);
            }

            if (!edges.containsKey(destinationEdge)) {
                List<Integer> list = new ArrayList<>();
                list.add(sourceEdge);
                edges.put(destinationEdge, list);
            } else {
                List<Integer> list = edges.get(destinationEdge);
                list.add(sourceEdge);
                edges.put(destinationEdge, list);
            }

        }

        int current = 0;
        if (presenOfCat[1] == 1) {
            current++;
        }

        System.out.println(getRestaurent(edges, presenOfCat, current, 1, m));
    }

    private static long getRestaurent(Map<Integer, List> edges, int[] presenOfCat, int current, int root, int m) {

        if (!edges.containsKey(root))
            return 1;

        List<Integer> connectedVertices = edges.get(root);
        long count = 0;
        for (int i = 0; i < connectedVertices.size(); i++) {

            List<Integer> removeList = edges.get(connectedVertices.get(i));
            if (removeList.contains(root)) {
                removeList.remove(new Integer(root));
                if (removeList.size() == 0)
                    edges.remove(connectedVertices.get(i));
                else
                    edges.put(connectedVertices.get(i), removeList);
            }

            int localCurrent = current;
            if (presenOfCat[connectedVertices.get(i)] == 1) {
                localCurrent++;
            } else
                localCurrent = 0;
            if (localCurrent <= m)
                count += getRestaurent(edges, presenOfCat, localCurrent, connectedVertices.get(i), m);
        }

        return count;

    }

    public static class MyScanner {

        BufferedReader br;
        StringTokenizer st;

        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

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

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

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

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

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

    }

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.*;
import java.util.Map.Entry;

public class Main {

    public static PrintWriter out;

    public static void main(String args[]) {

        MyScanner in = new MyScanner();
        int n = in.nextInt();
        int m = in.nextInt();
        int[] presenOfCat = new int[n + 1];
        for (int i = 1; i <= n; i++) {
            presenOfCat[i] = in.nextInt();
        }

        Map<Integer, List> edges = new TreeMap<Integer, List>();
        for (int i = 0; i < n - 1; i++) {
            int sourceEdge = in.nextInt();
            int destinationEdge = in.nextInt();
            if (!edges.containsKey(sourceEdge)) {
                List<Integer> list = new ArrayList<>();
                list.add(destinationEdge);
                edges.put(sourceEdge, list);
            } else {
                List<Integer> list = edges.get(sourceEdge);
                list.add(destinationEdge);
                edges.put(sourceEdge, list);
            }
        }

        int current = 0;
        if (presenOfCat[1] == 1) {
            current++;
        }

        System.out.println(getRestaurent(edges, presenOfCat, current, 1, m));
    }

    private static long getRestaurent(Map<Integer, List> edges, int[] presenOfCat, int current, int root, int m) {

        if (!edges.containsKey(root))
            return 1;

        List<Integer> connectedVertices = edges.get(root);
        long count = 0;
        for (int i = 0; i < connectedVertices.size(); i++) {
            int localCurrent = current;
            if (presenOfCat[connectedVertices.get(i)] == 1) {
                localCurrent++;
            } else
                localCurrent = 0;
            if (localCurrent <= m)
                count += getRestaurent(edges, presenOfCat, localCurrent, connectedVertices.get(i), m);
        }

        return count;

    }

    public static class MyScanner {

        BufferedReader br;
        StringTokenizer st;

        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

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

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

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

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

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

    }

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;
import java.util.Random;
import java.util.Stack;
import java.util.StringTokenizer;

public class TaskRunner {

    public static List<Integer>[] g;
    public static boolean[] prime;
    public static boolean[] visited;
    public static StringTokenizer st;
    public static BufferedReader br;
    public static PrintWriter out;
    public static int[] tree;
    public static boolean[][] visit;
    public static int m;
    public static int resh = 0;
    public static int[] a;

    public static void main(String... args) throws IOException {

        // br= new BufferedReader(new FileReader("input.txt"));
        // out = new PrintWriter("output.txt");

        br = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        int n = nextInt();
        m = nextInt();
        a = readIntArray(n);
        g = new List[n];
        for (int i =0;i<n;i++) {
            g[i] = new ArrayList<Integer>();
        }
        for (int i = 0; i < n-1; i++) {
            int x = nextInt();
            int y = nextInt();
            x--;y--;
            if(x<y)
                g[x].add(y);
            else
                g[y].add(x);
        }
        visited= new boolean[n];
        dfs(0,a[0]);
//      bfs(0,way);
        out.print(resh);
        out.close();
    }

    public static long gcd(long a, long b) {
        return b > 0 ? gcd(b, a % b) : a;
    }

    public static long lcd(long a, long b) {
        return a / gcd(a, b) * b;
    }
    public static void bfs(int v,List<Integer> way)
    {
        Queue<Integer> queue = new LinkedList<Integer>();
        queue.add(v);
        while(!queue.isEmpty())
        {
            int p = queue.poll();
            visited[p]=true;
            way.add(p);
            for (Integer x : g[p]) {
                if(!visited[x])
                    queue.add(x);
            }
        }
    }
    public static void dfs2(int v,List<Integer> way)
    {
        Stack<Integer> queue = new Stack<Integer>();
        queue.add(v);
        while(!queue.isEmpty())
        {
            int p = queue.pop();
            visited[p]=true;
            way.add(p);
            for (Integer x : g[p]) {
                if(!visited[x])
                    queue.add(x);
            }
        }
    }
    public static void dfs(int v, int currM) {
        visited[v] = true;
        if(g[v].size()==0 && currM<=m)
            resh++;
        for (int i = 0; i < g[v].size(); i++) {
            int p = g[v].get(i);
            if (!visited[p]) {
                if(a[p]==1)
                {
                    if(currM+1<=m)
                        dfs(p,currM+1);
                }
                else
                    dfs(p,0);
            }
        }
    }

    public static void Resheto(int n) {
        prime[0] = prime[1] = false;
        for (int i = 2; i <= n; ++i)
            if (prime[i])
                if (i * 1l * i <= n)
                    for (int j = i * i; j <= n; j += i)
                        prime[j] = false;
    }

    public static double len(Point a, Point b) {
        return Math.sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
    }

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

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

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

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

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

    }

    public static void printArray(int[] arr) throws IOException {
        for (int anArr : arr)
            out.print(anArr + " ");

    }

    public static int[] shuffleArray(int[] arr) {
        Random rnd = new Random();

        int n = arr.length;
        int temp;
        int ind;
        while (n > 1) {
            ind = rnd.nextInt(n--);
            temp = arr[ind];
            arr[ind] = arr[n];
            arr[n] = temp;
        }

        return arr;
    }
}

class Point {
    public int x;
    public int y;

    public Point(int x, int y) {
        this.x = x;
        this.y = y;
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;
import java.util.Random;
import java.util.Stack;
import java.util.StringTokenizer;

public class TaskRunner {

    public static List<Integer>[] g;
    public static boolean[] prime;
    public static boolean[] visited;
    public static StringTokenizer st;
    public static BufferedReader br;
    public static PrintWriter out;
    public static int[] tree;
    public static boolean[][] visit;
    public static int m;
    public static int resh = 0;
    public static int[] a;

    public static void main(String... args) throws IOException {

        // br= new BufferedReader(new FileReader("input.txt"));
        // out = new PrintWriter("output.txt");

        br = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        int n = nextInt();
        m = nextInt();
        a = readIntArray(n);
        g = new List[n];
        for (int i =0;i<n;i++) {
            g[i] = new ArrayList<Integer>();
        }
        for (int i = 0; i < n-1; i++) {
            int x = nextInt();
            int y = nextInt();
            x--;y--;

                g[x].add(y);

                g[y].add(x);
        }
        visited= new boolean[n];
        dfs(0,a[0]);
//      bfs(0,way);
        out.print(resh);
        out.close();
    }

    public static long gcd(long a, long b) {
        return b > 0 ? gcd(b, a % b) : a;
    }

    public static long lcd(long a, long b) {
        return a / gcd(a, b) * b;
    }
    public static void bfs(int v,List<Integer> way)
    {
        Queue<Integer> queue = new LinkedList<Integer>();
        queue.add(v);
        while(!queue.isEmpty())
        {
            int p = queue.poll();
            visited[p]=true;
            way.add(p);
            for (Integer x : g[p]) {
                if(!visited[x])
                    queue.add(x);
            }
        }
    }
    public static void dfs2(int v,List<Integer> way)
    {
        Stack<Integer> queue = new Stack<Integer>();
        queue.add(v);
        while(!queue.isEmpty())
        {
            int p = queue.pop();
            visited[p]=true;
            way.add(p);
            for (Integer x : g[p]) {
                if(!visited[x])
                    queue.add(x);
            }
        }
    }
    public static void dfs(int v, int currM) {
        visited[v] = true;
//      if(g[v].size()==0 && currM<=m)
//          resh++;
        int c=0;
        for (int i = 0; i < g[v].size(); i++) {
            int p = g[v].get(i);
            if (!visited[p]) {
                if(a[p]==1)
                {
                    if(currM+1<=m)
                        dfs(p,currM+1);
                }
                else
                    dfs(p,0);
            }
            else{
                c++;
            }
        }
        if(c==g[v].size()&&currM<=m)
            resh++;
    }

    public static void Resheto(int n) {
        prime[0] = prime[1] = false;
        for (int i = 2; i <= n; ++i)
            if (prime[i])
                if (i * 1l * i <= n)
                    for (int j = i * i; j <= n; j += i)
                        prime[j] = false;
    }

    public static double len(Point a, Point b) {
        return Math.sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
    }

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

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

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

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

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

    }

    public static void printArray(int[] arr) throws IOException {
        for (int anArr : arr)
            out.print(anArr + " ");

    }

    public static int[] shuffleArray(int[] arr) {
        Random rnd = new Random();

        int n = arr.length;
        int temp;
        int ind;
        while (n > 1) {
            ind = rnd.nextInt(n--);
            temp = arr[ind];
            arr[ind] = arr[n];
            arr[n] = temp;
        }

        return arr;
    }
}

class Point {
    public int x;
    public int y;

    public Point(int x, int y) {
        this.x = x;
        this.y = y;
    }
}


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

public class Codeforces580C {
	public static int leafCount(ArrayList<ArrayList<Integer>> tree, int root, int numCats, int maxCats, boolean[] hasCat)
	{
		if(numCats > maxCats)
			return 0;
		if(tree.get(root).size() == 0)
			return 1;
		ArrayList<Integer> children = tree.get(root);
		int sum = 0;
		for(int i = 0; i < children.size(); i++)
		{
			int child = children.get(i);
			if(hasCat[child])
				sum += leafCount(tree, child, numCats + 1, maxCats, hasCat);
			else
				sum += leafCount(tree, child, 0, maxCats, hasCat);
		}
		return sum;
	}
	public static void main(String[] args) {
		try
		{
			BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
			StringTokenizer st = new StringTokenizer(f.readLine());
			int n = Integer.parseInt(st.nextToken());
			int m = Integer.parseInt(st.nextToken());
			boolean[] hasCat = new boolean[n];
			st = new StringTokenizer(f.readLine());
			for(int i = 0; i < n; i++)
			{
				if(st.nextToken().equals("1"))
					hasCat[i] = true;
			}
			ArrayList<ArrayList<Integer>> tree = new ArrayList<ArrayList<Integer>>();
			for(int i = 0; i < n; i++)
				tree.add(new ArrayList<Integer>());
			for(int i = 0; i < n - 1; i++)
			{
				st = new StringTokenizer(f.readLine());
				int parent = Integer.parseInt(st.nextToken()) - 1;
				int child = Integer.parseInt(st.nextToken()) - 1;
				tree.get(parent).add(child);
			}
			if(hasCat[0])
				System.out.println(leafCount(tree, 0, 1, m, hasCat));
			else
				System.out.println(leafCount(tree, 0, 0, m, hasCat));
		}
		catch(IOException e)
		{
			System.out.println(e);
		}

	}

}


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

public class Codeforces580C {
	public static int leafCount(ArrayList<ArrayList<Integer>> tree, int rootParent, int root, int numCats, int maxCats, boolean[] hasCat)
	{
		if(numCats > maxCats)
			return 0;
		if(root != 0 && tree.get(root).size() == 1)
			return 1;
		ArrayList<Integer> children = tree.get(root);
		int sum = 0;
		for(int i = 0; i < children.size(); i++)
		{
			int child = children.get(i);
			if(child == rootParent)
				continue;
			if(hasCat[child])
				sum += leafCount(tree, root, child, numCats + 1, maxCats, hasCat);
			else
				sum += leafCount(tree, root, child, 0, maxCats, hasCat);
		}
		return sum;
	}
	public static void main(String[] args) {
		try
		{
			BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
			StringTokenizer st = new StringTokenizer(f.readLine());
			int n = Integer.parseInt(st.nextToken());
			int m = Integer.parseInt(st.nextToken());
			boolean[] hasCat = new boolean[n];
			st = new StringTokenizer(f.readLine());
			for(int i = 0; i < n; i++)
			{
				if(st.nextToken().equals("1"))
					hasCat[i] = true;
			}
			ArrayList<ArrayList<Integer>> tree = new ArrayList<ArrayList<Integer>>();
			for(int i = 0; i < n; i++)
				tree.add(new ArrayList<Integer>());
			for(int i = 0; i < n - 1; i++)
			{
				st = new StringTokenizer(f.readLine());
				int parent = Integer.parseInt(st.nextToken()) - 1;
				int child = Integer.parseInt(st.nextToken()) - 1;
				tree.get(parent).add(child);
				tree.get(child).add(parent);
			}
			if(hasCat[0])
				System.out.println(leafCount(tree, -1, 0, 1, m, hasCat));
			else
				System.out.println(leafCount(tree, -1, 0, 0, m, hasCat));
		}
		catch(IOException e)
		{
			System.out.println(e);
		}

	}

}


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

public class Main {
public static int n,m,x,y,i,result;
public static boolean[] visited,catPresence;
public static ArrayList<Integer>[] adjacencyList;
public static ArrayList<Integer> leaves;

    @SuppressWarnings("unchecked")
    public static void main(String[] args) throws Exception{
BufferedReader br =new BufferedReader(new InputStreamReader(System.in));
String[] parts=br.readLine().split(" ");
 n=Integer.parseInt(parts[0]);
 m=Integer.parseInt(parts[1]);
 //System.out.println("n:"+n);
 //System.out.println("m:"+m);
 visited= new boolean[n];
 catPresence=new boolean[n];
 adjacencyList= new ArrayList[n];
 //Arrays.fill(adjacencyList,new ArrayList<Integer>());

parts=br.readLine().split(" ");
for( i=0;i<n;i++){
    catPresence[i]=(parts[i]).equals("1");
    adjacencyList[i]=new ArrayList<Integer>();
}
for( i=0;i<n-1;i++){
    parts=br.readLine().split(" ");
    x=Integer.parseInt(parts[0])-1;
    y=Integer.parseInt(parts[1])-1;

    //if(!adjacencyList[x].contains(y))
    adjacencyList[x].add(y);
    //if(!adjacencyList[y].contains(x))
    adjacencyList[y].add(x);

}
leaves=new ArrayList<Integer>();
for( i=1;i<n;i++){
    if(adjacencyList[i].size()==1)
    {   leaves.add(i);
    //System.out.println("ADDED:"+i);
    }
}
depthFirstSearch(0,0);
result=0;
for(Integer I:leaves){
    if(visited[I])
        result++;
}
System.out.println(result);

br.close();
    }
public static void depthFirstSearch(int Vertex, int Cats){
    if(!catPresence[Vertex])
        Cats=0;
    else
        Cats++;
    if(Cats>m)
        return;
    visited[Vertex]=true;
    for(int c:adjacencyList[Vertex])
        if(!visited[c])
            depthFirstSearch(c,Cats);

}
}


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

public class Main {
public static int n,m,x,y,i,result;
public static boolean[] visited,catPresence;
public static ArrayList<Integer>[] adjacencyList;
public static ArrayList<Integer> leaves;

    @SuppressWarnings("unchecked")
    public static void main(String[] args) throws Exception{
BufferedReader br =new BufferedReader(new InputStreamReader(System.in));
String[] parts=br.readLine().split(" ");
 n=Integer.parseInt(parts[0]);
 m=Integer.parseInt(parts[1]);
 //System.out.println("n:"+n);
 //System.out.println("m:"+m);
 visited= new boolean[n];
 catPresence=new boolean[n];
 adjacencyList= new ArrayList[n];
 //Arrays.fill(adjacencyList,new ArrayList<Integer>());

parts=br.readLine().split(" ");
for( i=0;i<n;i++){
    catPresence[i]=(parts[i]).equals("1");
    adjacencyList[i]=new ArrayList<Integer>();
}
for( i=0;i<n-1;i++){
    parts=br.readLine().split(" ");
    x=Integer.parseInt(parts[0])-1;
    y=Integer.parseInt(parts[1])-1;

    if(!adjacencyList[x].contains(y))
    adjacencyList[x].add(y);
    if(!adjacencyList[y].contains(x))
    adjacencyList[y].add(x);

}
leaves=new ArrayList<Integer>();
for( i=0;i<n;i++){
    if(adjacencyList[i].size()==1)
        leaves.add(i);
}
depthFirstSearch(0,0);
result=0;
for(Integer I:leaves){
    if(visited[I])
        result++;
}
System.out.println(result);

br.close();
    }
public static void depthFirstSearch(int Vertex, int Cats){
    if(!catPresence[Vertex])
        Cats=0;
    else
        Cats++;
    if(Cats>m)
        return;
    visited[Vertex]=true;
    for(int c:adjacencyList[Vertex])
        if(!visited[c])
            depthFirstSearch(c,Cats);

}
}


import java.util.*;

public class Solution{

    static int count=0;

    static void calc(int root,List<List<Integer>> adj,int par,int curr,int tag[],int m){
        if(tag[root]==1)
            curr++;
        else{
            if(curr>m)
                return;
            curr=0;
        }
        if(root!=0 && adj.get(root).size()==1 && curr<=m){
        count++;
        //System.out.println(root);
        }
        Iterator<Integer> it=adj.get(root).iterator();
        while(it.hasNext()){
            int temp=it.next();
            if(temp!=par){
                calc(temp,adj,root,curr,tag,m);
            }
        }
    }

    public static void main(String[] args){
            Scanner in = new Scanner(System.in);
            int n=in.nextInt(),m=in.nextInt();
            int tag[]=new int[n];
            List<List<Integer>> adj=new ArrayList<List<Integer>>();
            for(int i=0;i<n;i++){
                tag[i]=in.nextInt();
                adj.add(new ArrayList<Integer>());
            }
            for(int i=0;i<n-1;i++){
                int u=in.nextInt(),v=in.nextInt();
                adj.get(u-1).add(v-1);
                adj.get(v-1).add(u-1);
            }
            calc(0,adj,-1,0,tag,m);
            System.out.println(count);
            in.close();
        }

    }


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

public class CF_580C_KefaAndPark
{
    public static void main(String[] args) throws IOException
    {
        BufferedReader in = new BufferedReader( new InputStreamReader(System.in));
        StringBuilder out = new StringBuilder("");
        String line, lines[];
        int n, m, x, y;
        boolean flags[];
        lines = in.readLine().trim().split("\\s+");
        n = Integer.parseInt(lines[0]);
        m = Integer.parseInt(lines[1]);
        lines = in.readLine().trim().split("\\s+");
        flags = new boolean[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; i++ )
        {
            if ( lines[i].equals("1") ) flags[i] = true;
        }
        for( int i = 0; i < n-1; i++ )
        {
            lines = in.readLine().trim().split("\\s+");
            x = Integer.parseInt(lines[0])-1;
            y = Integer.parseInt(lines[1])-1;
            graph[x].add(y);
            graph[y].add(x);
        }
        Queue<Integer> q = new LinkedList<Integer>();
        Queue<Integer> cats = new LinkedList<Integer>();
        boolean visited[] = new boolean[n];
        q.add(0);
        cats.add(0);
        int node, cat;
        int count = 0;
        while( !q.isEmpty())
        {
            node = q.poll();
            cat = cats.poll();
            //System.out.println(node+" "+cat);
            if ( visited[node] ) continue;
            if ( flags[node] ) cat++;
            else cat = 0;
            visited[node] = true;
            if ( cat > m ) continue;
            if ( graph[node].size() == 1) count++;
            for( int i = 0; i < graph[node].size(); i++ )
            {
                q.add(graph[node].get(i));
                cats.add( cat );
            }
        }
        System.out.println(count);
    }
}


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

public class CF_580C_KefaAndPark
{
    public static void main(String[] args) throws IOException
    {
        BufferedReader in = new BufferedReader( new InputStreamReader(System.in));
        StringBuilder out = new StringBuilder("");
        String line, lines[];
        int n, m, x, y;
        boolean flags[];
        lines = in.readLine().trim().split("\\s+");
        n = Integer.parseInt(lines[0]);
        m = Integer.parseInt(lines[1]);
        lines = in.readLine().trim().split("\\s+");
        flags = new boolean[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; i++ )
        {
            if ( lines[i].equals("1") ) flags[i] = true;
        }
        for( int i = 0; i < n-1; i++ )
        {
            lines = in.readLine().trim().split("\\s+");
            x = Integer.parseInt(lines[0])-1;
            y = Integer.parseInt(lines[1])-1;
            graph[x].add(y);
            graph[y].add(x);
        }
        Queue<Integer> q = new LinkedList<Integer>();
        Queue<Integer> cats = new LinkedList<Integer>();
        boolean visited[] = new boolean[n];
        q.add(0);
        cats.add(0);
        int node, cat;
        int count = 0;
        while( !q.isEmpty())
        {
            node = q.poll();
            cat = cats.poll();
            //System.out.println(node+" "+cat);
            if ( visited[node] ) continue;
            if ( flags[node] ) cat++;
            else cat = 0;
            visited[node] = true;
            if ( cat > m ) continue;
            if ( graph[node].size() == 1 && node != 0) count++;
            for( int i = 0; i < graph[node].size(); i++ )
            {
                q.add(graph[node].get(i));
                cats.add( cat );
            }
        }
        System.out.println(count);
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.StringTokenizer;

public class Main {

	static IO io;
	static HashSet<Integer> set;
	static int ans = 0;
	static node[] tree;
	static int n , m;
	public static void main(String args[]) throws Exception {

		io = new IO();
		io.init();
		//------------------------------------------------

		n = io.nextInt();
		m = io.nextInt();

		tree = new node[n];

		for( int  i = 0 ; i < n ; ++i ){
			int temp = io.nextInt();
			if( temp == 1 )
			tree[i] = new node(true);
			else
				tree[i] = new node(false);
		}

		for( int i  = 0 ; i < n-1 ; ++i ){
			int a = io.nextInt()-1;
			int b = io.nextInt()-1;

			tree[a].children.add(b);
			tree[b].children.add(a);
		}

		if( tree[0].hasCat)
			tree[0].countInclusive = 1;

		for( int i : tree[0].children){

			bfs(i,0);
		}
		System.out.println( ans);
		//------------------------------------------------
		io.destroy();

	}

	static void bfs(int cur, int parent){
		if( tree[cur].hasCat )
			tree[cur].countInclusive = tree[parent].countInclusive + 1;
		else tree[cur].countInclusive = 0 ;

		if( tree[cur].countInclusive > m) return;

		if( tree[cur].children.size() == 1 )
			ans++;
		else
		{
			for( int i : tree[cur].children){
				if( i != parent){
					bfs(i,cur);
				}
			}
		}

	}

	static class pair implements Comparable<pair>{
		int money, factor;
		pair( int money,int factor){
			this.money = money;
			this.factor = factor;
		}

		public int compareTo( pair p ){

			if( money < p.money) return -1;
			else if( money > p.money ) return +1;
			else if( factor < p.factor ) return -1;
			else if( factor > p.factor) return +1;
			else return 0;
		}
	}

	static class node {
		boolean hasCat;
		int countInclusive;
		boolean failed;
		ArrayList<Integer> children;

		node(boolean a){
			hasCat = a;
			countInclusive = 0 ;
			failed = false;
			children = new ArrayList<Integer>();
		}

	}

	static long gcd( long a , long b ){

		if( a == 0 ) return b;
		if( b == 0 )return a;
		if( a > b ) return gcd( a%b,b);
		else return gcd(a,b%a);

	}

	static class IO{

		BufferedReader reader;
		StringTokenizer tokenizer;
		PrintWriter writer;

		public void init() {
			try {
				reader = new BufferedReader(new InputStreamReader(System.in),8*1024);
				writer = new PrintWriter(System.out);
			} catch (Exception e) {
				e.printStackTrace();
				System.exit(261);
			}
		}

		void destroy() {
			writer.close();
			System.exit(0);
		}

		void print(Object... objects) {
			for (int i = 0; i < objects.length; i++) {
				if (i != 0)
					writer.print(' ');
				writer.print(objects[i]);
			}
		}

		void println(Object... objects) {
			print(objects);
			writer.println();
		}

		String nextLine() throws IOException {
			return reader.readLine();
		}

		String nextToken() throws IOException {
			while (tokenizer == null || !tokenizer.hasMoreTokens())
				tokenizer = new StringTokenizer(nextLine());
			return tokenizer.nextToken();
		}

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

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

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


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

public class Main {
	static int n,m,res=0;
	static boolean[] cats;
	static ArrayList<Integer>[] adj;
	static boolean[] v;

	static void dfs(int i,int cnt){
		v[i]=true;
		if(cnt>m)return;
		boolean inside=false;
		for(int j=0;j<adj[i].size();j++){
			int curr = adj[i].get(j);
			if(!v[curr]){
				inside=true;
				if(cats[curr])
					dfs(curr,cnt+1);
				else
					dfs(curr,0);
			}
		}
		if(!inside && cnt<=m){
			res++;
		}
	}
	public static void main(String[] args)throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder out = new StringBuilder();
		String[] in;
		in = br.readLine().split(" ");
		n = Integer.parseInt(in[0]); m = Integer.parseInt(in[1]);
		cats = new boolean[n+1];
		adj = new ArrayList[n+1];
		v = new boolean[n+1];
		adj[0] = new ArrayList<Integer>();
		in = br.readLine().split(" ");
		for(int i=0;i<n;i++){
			adj[i+1]=new ArrayList<Integer>();
			if(in[i].charAt(0)=='1')
				cats[i+1]=true;
		}
		for(int i=0;i<n-1;i++){
			in = br.readLine().split(" ");
			int from = Integer.parseInt(in[0]) , to = Integer.parseInt(in[1]);
			adj[from].add(to);
			adj[to].add(from);
		}
		int start = 0;
		if(cats[1])start=1;
		dfs(1,start);
		System.out.println(res);
	}
}


/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

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

    /**
     * @param args the command line arguments
     */
    static ArrayList<Integer> adj[];
    static int arr[];
    static int n,m;
    static int sol=0;
    static void dfs(int nd,int p,int curr,int add){
        if(arr[nd]==1){

            curr++;
        } else {

            curr=0;
        }
        if(curr>m){
            add=0;
        }
        boolean ok=true;
        for(int i=0;i<adj[nd].size();i++){

            int ch=adj[nd].get(i);
            if(ch==p)continue;
            ok=false;
            dfs(ch,nd,curr,add);
        }
        if(ok){

            sol+=add;
        }
    }
    public static void main(String[] args) {

        Scanner r = new Scanner(System.in);
        n=r.nextInt();
        m=r.nextInt();
        arr=new int[n+10];
        adj=new ArrayList[n+10];
        for(int i=1;i<=n;i++){

            adj[i]=new ArrayList<Integer>();
        }
        int a,b;
        for(int i=1;i<=n;i++){
            arr[i]=r.nextInt();
        }
        for(int i=1;i<n;i++){
            a=r.nextInt();
            b=r.nextInt();
            adj[a].add(b);
            adj[b].add(a);
        }
        dfs(1,1,0,1);
        System.out.println(sol);
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Queue;
import java.util.StringTokenizer;

public class C {

    /**
     * @param args
     * @throws IOException
     */
    public static void main(String[] args) throws IOException
    {
        int n = nextInt();
        int m = nextInt();
        int[] cat = new int[n];
        ArrayList<Integer>[] g = new ArrayList[n];
        for (int i = 0; i < n; i++)
        {
            cat[i] = nextInt();
            g[i] = new ArrayList<Integer>();
        }
        for (int i = 0; i < n - 1; i++)
        {
            int a = nextInt() - 1;
            int b = nextInt() - 1;
            g[a].add(b);
            g[b].add(a);
        }

        Queue<Integer> q = new LinkedList<Integer>();
        q.add(0);
        q.add(-1);
        q.add(cat[0]);
        int count = 0;
        while (!q.isEmpty())
        {
            int node = q.poll();
            int parent = q.poll();
            int catsSoFar = q.poll();
            if (catsSoFar > m)
                continue;
            boolean leaf = true;
            for (int child : g[node])
                if (child != parent)
                {
                    leaf = false;
                    if (cat[child] == 0)
                    {
                        q.add(child);
                        q.add(node);
                        q.add(0);
                    } else if (catsSoFar + 1 <= m)
                    {
                        q.add(child);
                        q.add(node);
                        q.add(catsSoFar + 1);
                    }
                }
            if(leaf)
                count++;
        }
        System.out.println(count);
    }

    static BufferedReader reader = new BufferedReader(new InputStreamReader(
            System.in));
    static StringTokenizer tokenizer = null;

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

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

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

    static String nextToken() throws IOException
    {
        while (tokenizer == null || !tokenizer.hasMoreTokens())
        {
            tokenizer = new StringTokenizer(reader.readLine());
        }
        return tokenizer.nextToken();
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Queue;
import java.util.StringTokenizer;

public class C {

    /**
     * @param args
     * @throws IOException
     */
    public static void main(String[] args) throws IOException
    {
        int n = nextInt();
        int m = nextInt();
        int[] cat = new int[n];
        ArrayList<Integer>[] g = new ArrayList[n];
        for(int i = 0 ; i  < n;i++)
        {
            cat[i] = nextInt();
            g[i]  = new ArrayList<Integer>();
        }
        for(int i = 0 ; i  < n-1 ;i++)
        {
            int a = nextInt()-1;
            int b = nextInt()-1;
            g[a].add(b);
            g[b].add(a);
        }

        Queue<Integer> q =  new LinkedList<Integer>();
        q.add(0);
        q.add(-1);
        q.add(cat[0]);
        int count =0;
        while(!q.isEmpty())
        {
            int node = q.poll();
            int parent = q.poll();
            int catsSoFar = q.poll();
            if(catsSoFar > m)
                continue;
            if(g[node].size() <= 1)
                count++;
            else
            {
                for(int child:g[node])
                    if(child != parent)
                    {
                        if(cat[child] == 0)
                        {
                            q.add(child);
                            q.add(node);
                            q.add(0);
                        }else
                            if(catsSoFar+1 <= m)
                            {
                                q.add(child);
                                q.add(node);
                                q.add(catsSoFar+1);
                            }
                    }
            }
        }
        System.out.println(count);
    }

    static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    static StringTokenizer tokenizer = null;

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

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

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

    static String nextToken() throws IOException
    {
        while (tokenizer == null || !tokenizer.hasMoreTokens())
        {
            tokenizer = new StringTokenizer(reader.readLine());
        }
        return tokenizer.nextToken();
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Queue;
import java.util.StringTokenizer;

public class C {

    /**
     * @param args
     * @throws IOException
     */
    public static void main(String[] args) throws IOException
    {
        int n = nextInt();
        int m = nextInt();
        int[] cat = new int[n];
        ArrayList<Integer>[] g = new ArrayList[n];
        for(int i = 0 ; i  < n;i++)
        {
            cat[i] = nextInt();
            g[i]  = new ArrayList<Integer>();
        }
        for(int i = 0 ; i  < n-1 ;i++)
        {
            int a = nextInt()-1;
            int b = nextInt()-1;
            g[a].add(b);
            g[b].add(a);
        }

        Queue<Integer> q =  new LinkedList<Integer>();
        q.add(0);
        q.add(-1);
        q.add(cat[0]);
        int count =0;
        while(!q.isEmpty())
        {
            int node = q.poll();
            int parent = q.poll();
            int catsSoFar = q.poll();
            if(catsSoFar > m)
                continue;
            if(g[node].size() == 1)
                count++;
            else
            {
                for(int child:g[node])
                    if(child != parent)
                    {
                        if(cat[child] == 0)
                        {
                            q.add(child);
                            q.add(node);
                            q.add(0);
                        }else
                            if(catsSoFar+1 <= m)
                            {
                                q.add(child);
                                q.add(node);
                                q.add(catsSoFar+1);
                            }
                    }
            }
        }
        System.out.println(count);
    }

    static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    static StringTokenizer tokenizer = null;

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

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

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

    static String nextToken() throws IOException
    {
        while (tokenizer == null || !tokenizer.hasMoreTokens())
        {
            tokenizer = new StringTokenizer(reader.readLine());
        }
        return tokenizer.nextToken();
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Queue;
import java.util.StringTokenizer;

public class C {

    /**
     * @param args
     * @throws IOException
     */
    public static void main(String[] args) throws IOException
    {
        int n = nextInt();
        int m = nextInt();
        int[] cat = new int[n];
        ArrayList<Integer>[] g = new ArrayList[n];
        for(int i = 0 ; i  < n;i++)
        {
            cat[i] = nextInt();
            g[i]  = new ArrayList<Integer>();
        }
        for(int i = 0 ; i  < n-1 ;i++)
        {
            int a = nextInt()-1;
            int b = nextInt()-1;
            g[a].add(b);
            g[b].add(a);
        }

        Queue<Integer> q =  new LinkedList<Integer>();
        q.add(0);
        q.add(-1);
        q.add(cat[0]);
        int count =0;
        while(!q.isEmpty())
        {
            int node = q.poll();
            int parent = q.poll();
            int catsSoFar = q.poll();
            if(g[node].size() == 1)
                count++;
            else
            {
                for(int child:g[node])
                    if(child != parent)
                    {
                        if(cat[child] == 0)
                        {
                            q.add(child);
                            q.add(node);
                            q.add(0);
                        }else
                            if(catsSoFar+1 <= m)
                            {
                                q.add(child);
                                q.add(node);
                                q.add(catsSoFar+1);
                            }
                    }
            }
        }
        System.out.println(count);
    }

    static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    static StringTokenizer tokenizer = null;

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

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

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

    static String nextToken() throws IOException
    {
        while (tokenizer == null || !tokenizer.hasMoreTokens())
        {
            tokenizer = new StringTokenizer(reader.readLine());
        }
        return tokenizer.nextToken();
    }
}


//package codeforces;

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

public class KefaAndPark
{
	static boolean visited[];
	static Vertex[] graph;
	static int maxCats;

	public static void main(String[] args)
	{
		MyScanner scan = new MyScanner();

		int N = scan.nextInt();
		maxCats = scan.nextInt();

		graph = new Vertex[N+1];
		graph[0] = new Vertex(0, false);
		for (int i = 1; i <= N; i++) {
			graph[i] = new Vertex(i, scan.nextInt()==1);

		}

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

			graph[x].adjacencies.add(y);
			graph[y].adjacencies.add(x);

		}
		visited = new boolean[N+1];

		dfs(1, 0);
		System.out.println(ways);
	}

	static int ways = 0;
	public static void dfs(int v, int catsSoFar)
	{
		visited[v] = true;
		if (graph[v].hasCat)
		{
			catsSoFar++;
			if (catsSoFar > maxCats) {
				return;
			}
		} else {
			catsSoFar = 0;
		}

		if (graph[v].adjacencies.size()==1) {
			ways++;
		}
		else
		{
			for(Integer e: graph[v].adjacencies){
				if (!visited[e]) {
					dfs(e, catsSoFar);
				}
			}
		}
	}

	static class Vertex
	{
		public int id;
		public boolean hasCat;
		public ArrayList<Integer> adjacencies;
		public Vertex(int argId, boolean hasCat) {
			id = argId;
			adjacencies = new ArrayList<>();
			this.hasCat = hasCat;
		}
	}

	//--------------------------------------------------------
	public static class MyScanner {
		BufferedReader br;
		StringTokenizer st;

		public MyScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

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

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

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

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

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


//package codeforces;

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

public class KefaAndPark
{
	static Vertex[] graph;
	static int maxCats;

	public static void main(String[] args)
	{
		MyScanner scan = new MyScanner();

		int N = scan.nextInt();
		maxCats = scan.nextInt();

		graph = new Vertex[N+1];
		graph[0] = new Vertex(0, false);
		for (int i = 1; i <= N; i++) {
			graph[i] = new Vertex(i, scan.nextInt()==1);

		}

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

			graph[x].adjacencies.add(y);
			//graph[y].adjacencies.add(x);

		}

		dfs(1, 0);
		System.out.println(ways);
	}

	static int ways = 0;
	public static void dfs(int v, int catsSoFar)
	{
		if (graph[v].hasCat)
		{
			catsSoFar++;
			if (catsSoFar > maxCats) {
				return;
			}
		} else {
			catsSoFar = 0;
		}

		if (graph[v].adjacencies.isEmpty()) {
			ways++;
		}
		else
		{
			for(Integer e: graph[v].adjacencies){
				dfs(e, catsSoFar);
			}
		}
	}

	static class Vertex
	{
		public int id;
		public boolean hasCat;
		public ArrayList<Integer> adjacencies;
		public Vertex(int argId, boolean hasCat) {
			id = argId;
			adjacencies = new ArrayList<>();
			this.hasCat = hasCat;
		}
	}

	//--------------------------------------------------------
	public static class MyScanner {
		BufferedReader br;
		StringTokenizer st;

		public MyScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

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

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

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

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

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


//package codeforces;

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

public class KefaAndPark
{
	static boolean visited[];
	static Vertex[] graph;
	static int maxCats;

	public static void main(String[] args)
	{
		MyScanner scan = new MyScanner();

		int N = scan.nextInt();
		maxCats = scan.nextInt();

		graph = new Vertex[N+1];
		graph[0] = new Vertex(0, false);
		for (int i = 1; i <= N; i++) {
			graph[i] = new Vertex(i, scan.nextInt()==1);

		}

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

			graph[x].adjacencies.add(y);
			graph[y].adjacencies.add(x);

		}
		visited = new boolean[N+1];

		dfs(1, 0);
		System.out.println(ways);
	}

	static int ways = 0;
	public static void dfs(int v, int catsSoFar)
	{
		visited[v] = true;
		if (graph[v].hasCat)  {
			catsSoFar++;
		} else {
			catsSoFar = 0;
		}

		if (catsSoFar > maxCats) {
			return;
		}

		if (graph[v].adjacencies.size()==1 && v !=1) {
			ways++;
			return;
		}
		for(Integer e: graph[v].adjacencies){
			if (!visited[e]) {
				dfs(e, catsSoFar);
			}
		}
	}

	static class Vertex
	{
		public int id;
		public boolean hasCat;
		public ArrayList<Integer> adjacencies;
		public Vertex(int argId, boolean hasCat) {
			id = argId;
			adjacencies = new ArrayList<>();
			this.hasCat = hasCat;
		}
	}

	//--------------------------------------------------------
	public static class MyScanner {
		BufferedReader br;
		StringTokenizer st;

		public MyScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

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

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

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

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

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


//package codeforces;

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

public class KefaAndPark
{
	static boolean visited[];
	static Vertex[] graph;
	static int maxCats;

	public static void main(String[] args)
	{
		MyScanner scan = new MyScanner();

		int N = scan.nextInt();
		maxCats = scan.nextInt();

		graph = new Vertex[N+1];
		graph[0] = new Vertex(0, false);
		for (int i = 1; i <= N; i++) {
			graph[i] = new Vertex(i, scan.nextInt()==1);

		}

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

			graph[x].adjacencies.add(y);
			//graph[y].adjacencies.add(x);

		}
		visited = new boolean[N+1];

		dfs(1, 0);
		System.out.println(ways);
	}

	static int ways = 0;
	public static void dfs(int v, int catsSoFar)
	{
		visited[v] = true;
		if (graph[v].hasCat)
		{
			catsSoFar++;
			if (catsSoFar > maxCats) {
				return;
			}
		} else {
			catsSoFar = 0;
		}

		if (graph[v].adjacencies.isEmpty()) {
			ways++;
		}
		else
		{
			for(Integer e: graph[v].adjacencies){
				if (!visited[e]) {
					dfs(e, catsSoFar);
				}
			}
		}
	}

	static class Vertex
	{
		public int id;
		public boolean hasCat;
		public ArrayList<Integer> adjacencies;
		public Vertex(int argId, boolean hasCat) {
			id = argId;
			adjacencies = new ArrayList<>();
			this.hasCat = hasCat;
		}
	}

	//--------------------------------------------------------
	public static class MyScanner {
		BufferedReader br;
		StringTokenizer st;

		public MyScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

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

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

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

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

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


//package codeforces;

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

public class KefaAndPark
{
	static Vertex[] graph;
	static int maxCats;

	public static void main(String[] args)
	{
		MyScanner scan = new MyScanner();

		int N = scan.nextInt();
		maxCats = scan.nextInt();

		graph = new Vertex[N+1];
		graph[0] = new Vertex(0, false);
		for (int i = 1; i <= N; i++) {
			graph[i] = new Vertex(i, scan.nextInt()==1);

		}

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

			graph[x].adjacencies.add(y);
			//graph[y].adjacencies.add(x);

		}

		dfs(1, 0);
		System.out.println(ways);
	}

	static int ways = 0;
	public static void dfs(int v, int catsSoFar)
	{
		if (graph[v].hasCat) {
			catsSoFar++;
		} else {
			catsSoFar = 0;
		}

		if (catsSoFar > maxCats) {
			return;
		}

		if (graph[v].adjacencies.isEmpty()) {
			ways++;
			return;
		}

		for(Integer e: graph[v].adjacencies){
			dfs(e, catsSoFar);
		}
	}

	static class Vertex
	{
		public int id;
		public boolean hasCat;
		public ArrayList<Integer> adjacencies;
		public Vertex(int argId, boolean hasCat) {
			id = argId;
			adjacencies = new ArrayList<>();
			this.hasCat = hasCat;
		}
	}

	//--------------------------------------------------------
	public static class MyScanner {
		BufferedReader br;
		StringTokenizer st;

		public MyScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

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

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

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

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

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


//package codeforces;

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

public class KefaAndPark
{
	static boolean visited[];
	static Vertex[] graph;
	static int maxCats;

	public static void main(String[] args)
	{
		MyScanner scan = new MyScanner();

		int N = scan.nextInt();
		maxCats = scan.nextInt();

		graph = new Vertex[N+1];
		graph[0] = new Vertex(0, false);
		for (int i = 1; i <= N; i++) {
			graph[i] = new Vertex(i, scan.nextInt()==1);

		}

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

			graph[x].adjacencies.add(y);
			//graph[y].adjacencies.add(x);

		}
		visited = new boolean[N+1];

		dfs(1, 0);
		System.out.println(ways);
	}

	static int ways = 0;
	public static void dfs(int v, int catsSoFar)
	{
		visited[v] = true;
		if (graph[v].hasCat)  {
			catsSoFar++;
		} else {
			catsSoFar = 0;
		}

		if (catsSoFar > maxCats) {
			return;
		}

		if (graph[v].adjacencies.size()==1 && v !=1) {
			ways++;
			return;
		}
		for(Integer e: graph[v].adjacencies){
			if (!visited[e]) {
				dfs(e, catsSoFar);
			}
		}
	}

	static class Vertex
	{
		public int id;
		public boolean hasCat;
		public ArrayList<Integer> adjacencies;
		public Vertex(int argId, boolean hasCat) {
			id = argId;
			adjacencies = new ArrayList<>();
			this.hasCat = hasCat;
		}
	}

	//--------------------------------------------------------
	public static class MyScanner {
		BufferedReader br;
		StringTokenizer st;

		public MyScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

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

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

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

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

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


//package codeforces;

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

public class KefaAndPark
{
	static Vertex[] graph;
	static int maxCats;

	public static void main(String[] args)
	{
		MyScanner scan = new MyScanner();

		int N = scan.nextInt();
		maxCats = scan.nextInt();

		graph = new Vertex[N+1];
		graph[0] = new Vertex(0, false);
		for (int i = 1; i <= N; i++) {
			graph[i] = new Vertex(i, scan.nextInt()==1);

		}

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

			graph[x].adjacencies.add(y);
			//graph[y].adjacencies.add(x);

		}

		dfs(1, 0);
		System.out.println(ways);
		ways = 0;
	}

	static int ways = 0;
	public static void dfs(int v, int catsSoFar)
	{
		if (graph[v].hasCat) {
			catsSoFar++;
		} else {
			catsSoFar = 0;
		}

		if (catsSoFar > maxCats) {
			return;
		}

		if (graph[v].adjacencies.isEmpty()) {
			ways++;
			return;
		}

		for(Integer e: graph[v].adjacencies){
			dfs(e, catsSoFar);
		}
	}

	static class Vertex
	{
		public int id;
		public boolean hasCat;
		public ArrayList<Integer> adjacencies;
		public Vertex(int argId, boolean hasCat) {
			id = argId;
			adjacencies = new ArrayList<>();
			this.hasCat = hasCat;
		}
	}

	//--------------------------------------------------------
	public static class MyScanner {
		BufferedReader br;
		StringTokenizer st;

		public MyScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

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

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

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

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

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


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.StringTokenizer;

public class Main
{
    int n;
    int threshold;
    int layer[];
    boolean visited[];
    ArrayList<ArrayList<Integer>> a;
    FastScanner in;
    PrintWriter out;

    public void solve() throws IOException
    {
        n = in.nextInt();
        threshold = in.nextInt();

        a = new ArrayList<ArrayList<Integer>>();
        visited = new boolean[n];
        layer = new int[n];

        for (int i = 0; i < layer.length; i++)
        {
            layer[i] = in.nextInt();
            a.add(new ArrayList<Integer>());
        }

        for (int i = 0; i < n - 1; i++)
        {
            int from = in.nextInt() - 1;
            int to = in.nextInt() - 1;
            a.get(from).add(to);
            a.get(to).add(from);
        }
        int count = bfs(0);
        out.println(count);
    }

    public int bfs(int start)
    {
        int count = 0;
        LinkedList<Integer> queue = new LinkedList<Integer>();
        queue.add(start);
        visited[start] = true;
        while (!queue.isEmpty())
        {
            start = queue.poll();
            boolean isLeaf = true;
            ArrayList<Integer> connectedTo = a.get(start);
            for (int i = 0; i < connectedTo.size(); i++)
            {
                int to = connectedTo.get(i);
                if ( !visited[to] )
                {
                    isLeaf = false;
                    if ( layer[start] != 0 && layer[to] != 0 )
                    {
                        layer[to] = layer[start] + 1;
                        if ( layer[to] > threshold )
                        {
                            continue;
                        }
                    }
                    queue.add(to);
                    visited[to] = true;
                }
            }
            if ( isLeaf )
            {
                count++;
            }
        }
        return count;
    }

    public void run()
    {
        try
        {
            in = new FastScanner();
            out = new PrintWriter(System.out, true);
            solve();
            out.flush();
            out.close();
        } catch (IOException e)
        {
            e.printStackTrace();
        }
    }

    class FastScanner
    {
        BufferedReader br;
        StringTokenizer st;

        FastScanner()
        {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

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

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

    public static void main(String[] arg)
    {
        new Main().run();
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.LinkedList;
import java.util.StringTokenizer;

public class Main
{
    int n;
    int threshold;
    int layer[];
    boolean visited[];
    boolean a[][];
    FastScanner in;
    PrintWriter out;

    public void solve() throws IOException
    {
        n = in.nextInt();
        threshold = in.nextInt();

        a = new boolean[n][n];
        visited = new boolean[n];
        layer = new int[n];

        for (int i = 0; i < layer.length; i++)
        {
            layer[i] = in.nextInt();
        }

        for (int i = 0; i < n - 1; i++)
        {
            int from = in.nextInt() - 1;
            int to = in.nextInt() - 1;
            a[from][to] = a[to][from] = true;
        }
        int count = bfs(0);
        out.println(count);
    }

    public int bfs(int start)
    {
        int count = 0;
        LinkedList<Integer> queue = new LinkedList<Integer>();
        queue.add(start);
        visited[start] = true;
        while (!queue.isEmpty())
        {
            start = queue.poll();
            boolean isLeaf = true;
            for (int i = 0; i < n; i++)
            {
                if ( a[start][i] && !visited[i] )
                {
                    isLeaf = false;
                    if ( layer[start] != 0 && layer[i] != 0 )
                    {
                        layer[i] = layer[start] + 1;
                        if ( layer[i] > threshold )
                        {
                            continue;
                        }
                    }
                    queue.add(i);
                    visited[i] = true;
                }
            }
            if ( isLeaf )
            {
                count++;
            }
        }
        return count;
    }

    public boolean isLeafNode(int row)
    {
        for (int i = 0; i < a[row].length; i++)
        {
            if ( a[row][i] )
            {
                return false;
            }
        }
        return true;
    }

    public void run()
    {
        try
        {
            in = new FastScanner();
            out = new PrintWriter(System.out, true);
            solve();
            out.flush();
            out.close();
        } catch (IOException e)
        {
            e.printStackTrace();
        }
    }

    class FastScanner
    {
        BufferedReader br;
        StringTokenizer st;

        FastScanner()
        {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

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

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

    public static void main(String[] arg)
    {
        new Main().run();
    }
}