import java.util.*;
class TreeLeaves {

    static List<Integer>[] G;
    static int[] nodeValue;
    static int count = 0;

    static void dfs(int node, int parent) {

        boolean isLeaf = true;

        for (int child : G[node]) {
            if (child != parent) {
                isLeaf = false;
                dfs(child, node);
            }
        }

        // Count only leaves whose value is 1
        if (isLeaf && nodeValue[node] == 1) {
            count++;
        }
    }

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();

        G = new ArrayList[N + 1];
        nodeValue = new int[N + 1];

        // Initialize graph
        for (int i = 1; i <= N; i++) {
            G[i] = new ArrayList<>();
        }

        // Node values
        for (int i = 1; i <= N; i++) {
            nodeValue[i] = sc.nextInt();
        }

        // Edges
        for (int i = 0; i < N - 1; i++) {
            int u = sc.nextInt();
            int v = sc.nextInt();

            G[u].add(v);
            G[v].add(u);
        }

        // Root the tree at node 1
        dfs(1, -1);

        System.out.println(count);

        sc.close();
    }
}