Java Easy DFS
The bug mentioned by hiepit@ below has been fixed.\n\n\nclass Solution {\n    int ans = 0;\n\n    public int minTime(int n, int[][] edges, List<Boolean> hasAppl
The bug mentioned by hiepit@ below has been fixed.\n\n```\nclass Solution {\n    int ans = 0;\n\n    public int minTime(int n, int[][] edges, List<Boolean> hasApple) {\n        Map<Integer, List<Integer>> graph = new HashMap<>();\n        for (int[] edge : edges) {\n            graph.putIfAbsent(edge[0], new ArrayList<>());\n            graph.putIfAbsent(edge[1], new ArrayList<>());\n            graph.get(edge[0]).add(edge[1]);\n            graph.get(edge[1]).add(edge[0]);\n        }\n        needToGo(graph, 0, -1, hasApple);\n\n        return ans;\n    }\n\n    private boolean needToGo(Map<Integer, List<Integer>> graph, int curNode, int prevNode, List<Boolean> hasApple) {\n        boolean res = hasApple.get(curNode);\n        for (int nxtNode : graph.getOrDefault(curNode, new ArrayList<>())) {\n            if (nxtNode != prevNode) {\n                if (needToGo(graph, nxtNode, curNode, hasApple)) {\n                    res = true;\n                    ans += 2;\n                }\n            }\n        }\n\n        return res;\n    }\n}\n```
['Java']