Java build Graph and DFS
There is a trick:\nthey put 0-2-1 as path.....\n\n4\n[[0,2],[0,3],[1,2]]\n[false,true,false,false]\n\nusually, should be 0-1-2;\n\n\nclass Solution {\n    Map<I
There is a trick:\nthey put 0-2-1 as path.....\n```\n4\n[[0,2],[0,3],[1,2]]\n[false,true,false,false]\n```\nusually, should be 0-1-2;\n\n```\nclass Solution {\n    Map<Integer, Node> map = new HashMap<>();\n    public int minTime(int n, int[][] edges, List<Boolean> hasApple) {\n        for (int i = 0; i < n; i++) {\n            final int val = i;\n            map.computeIfAbsent(val, k -> new Node(val));\n        }\n        for (int[] e : edges) {\n            Node p = map.get(e[0]), c = map.get(e[1]);\n            p.cs.add(c);\n            c.cs.add(p);\n        }\n        return dfs(map.get(0), new Node(-1), hasApple);\n    }\n    \n    public class Node{\n        List<Node> cs;  // short for childs\n        int val;\n        public Node(int val) {\n            this.val = val;\n            this.cs = new ArrayList<>();\n        }\n    }\n    \n    private int dfs(Node node, Node p, List<Boolean> hasApple) {\n        if (node == null) return 0;\n        int res = 0;\n        for (Node c : node.cs) {\n            if (c.val == p.val) continue;\n            res += dfs(c, node, hasApple);\n        }\n        return (res > 0 || hasApple.get(node.val)) ? res + (node.val > 0 ? 2 : 0) : 0;\n    }\n}\n```
[]