My Java Solution creating graph and doing DFS
\nclass Solution {\n    public int minTime(int n, int[][] edges, List<Boolean> hasApple) {\n        List<List<Integer>> adj = new ArrayList<>();\n        for (i
```\nclass Solution {\n    public int minTime(int n, int[][] edges, List<Boolean> hasApple) {\n        List<List<Integer>> adj = new ArrayList<>();\n        for (int i=0; i<n; i++)\n            adj.add(i, new LinkedList<>());\n        for (int []e: edges) {\n            adj.get(e[0]).add(e[1]);\n            adj.get(e[1]).add(e[0]);\n        }\n        boolean [] visited = new boolean[n];\n        visited[0] = true;\n        return dfs(adj, hasApple, 0, visited);\n    }\n    public int dfs(List<List<Integer>> adj, List<Boolean> hasApple, int v, boolean [] visited) {\n        if (adj.get(v) == null)\n            return 0;\n        int count = 0;\n        List<Integer> children = adj.get(v);\n        for (int child: children) {\n            if (!visited[child]) {\n                visited[child] = true;\n                count += dfs(adj, hasApple, child, visited);\n            }\n        }\n        if ((count>0 || hasApple.get(v)) && v != 0)\n            count += 2;\n        return count;\n    }\n}\n```
['Depth-First Search', 'Graph', 'Java']