JAVA DFS
\nclass Solution {\n    public int minTime(int n, int[][] edges, List<Boolean> hasApple) {\n        List<List<Integer>> paths = new ArrayList<>();\n        for(
```\nclass Solution {\n    public int minTime(int n, int[][] edges, List<Boolean> hasApple) {\n        List<List<Integer>> paths = new ArrayList<>();\n        for(int i=0;i<n;i++) paths.add(new ArrayList<>());\n        for(int[] e : edges){\n            paths.get(e[0]).add(e[1]);\n            paths.get(e[1]).add(e[0]);\n        }\n        return dfs(paths,0,hasApple,new boolean[n+1]);\n    }\n    \n    private int dfs(List<List<Integer>> paths,int curr,List<Boolean> hasApple,boolean[] visited){\n        visited[curr]=true;\n        int total = 0;\n        for(int cn : paths.get(curr)){\n            if(visited[cn]) continue;\n            total += dfs(paths,cn,hasApple,visited);\n        }\n        if((total>0 || hasApple.get(curr)) && curr!=0) total+=2;\n        return total;    \n    }\n}\n```
[]