Easy Approach using DFS JAVA
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n    public int minTime(int n, int[][] edges, List<Boolean> hasApple) {\n        List<List<Integer>> map = new ArrayList<>();\n\n        for(int i=0;i<n;i++)\n        {\n            map.add(new ArrayList<Integer>(0));\n        }\n        boolean visited[] = new boolean[n];\n\n        for(int[] e:edges){\n            map.get(e[0]).add(e[1]);\n            map.get(e[1]).add(e[0]);\n        }\n\n        return dfs(map,visited,hasApple,0);\n    }\n\n    private int dfs(List<List<Integer>> map,boolean[] visited,List<Boolean> hasApple,int index)\n    {\n        int result = 0;\n        visited[index] = true;\n\n        for(int i:map.get(index))\n        {\n            if(!visited[i])\n            {\n                result += dfs(map,visited,hasApple,i);\n            }\n        }\n\n        if(index == 0)\n        {\n            return result;\n        }\n\n        return result+=(hasApple.get(index) || result>0)?2:0;\n    }\n}\n```
['Depth-First Search', 'Java']