import java.util.*;


public class Main {
     class Vertex {
        int index;
        boolean hidden;
        List<Vertex> childs = new ArrayList<>();

        public Vertex(int index) {
            this.index = index;
        }
    }

    public static void main(String[] args) {
        new Main().run();
    }
    
    void run() {
        int n = 10;
        ArrayList<Vertex> tree = new ArrayList<>();
        HashMap<Integer, List<Integer>> childListMap = new HashMap<>();
        childListMap.put(0, Arrays.asList(1, 2, 3));
        childListMap.put(2, Arrays.asList(4));
        childListMap.put(3, Arrays.asList(7));
        childListMap.put(4, Arrays.asList(5, 6));
        childListMap.put(7, Arrays.asList(8, 9));

        HashSet<Integer> hiddenSet = new HashSet<>();
        hiddenSet.addAll(Arrays.asList(5, 6));

        Vertex[] vs = new Vertex[n];
        for (int i = 0; i < n; i++) {
            Vertex v = new Vertex(i);
            v.hidden = hiddenSet.contains(i);
            vs[i] = v;
        }
        for (int i = 0; i < n; i++) {
            if (childListMap.get(i) == null)
                continue;
            for (Integer childIndex : childListMap.get(i)) {
                vs[i].childs.add(vs[childIndex]);
            }
        }
        setHiddenForTree(vs[0]);
        printResult(vs);
    }

    void setHiddenForTree(Vertex root) {
        dfs(root);
    }

    boolean dfs(Vertex v) {
        if (v.hidden) {
            return true;
        }
        if (v.childs.isEmpty()){
            return v.hidden;
        }
        boolean allChildsHidden = true;
        for (Vertex child : v.childs) {
            allChildsHidden = allChildsHidden & dfs(child); //if at least one child isn't hidden, result of boolean product will be 'false'
        }
        if (allChildsHidden) {
            v.hidden = true;
        }
        return v.hidden;
    }
    
    void printResult(Vertex[] vs) {
        for (int i = 0; i < vs.length; i++) {
            System.out.println("vertex " + i + ": " + "hidden = " + vs[i].hidden);
        }
    }
}
