[Java] Easy DFS
```\nclass Solution {\n    static int time;\n    public static int dfs(List> g, int curr, int n, List hasApple, boolean[] visited) {\n        if(visited[curr]) 
```\nclass Solution {\n    static int time;\n    public static int dfs(List<List<Integer>> g, int curr, int n, List<Boolean> hasApple, boolean[] visited) {\n        if(visited[curr]) return 0;\n        int count = hasApple.get(curr) ? 1 : 0;\n        List<Integer> adj = g.get(curr);\n        visited[curr] = true;\n        for(int i = 0; i < adj.size(); i++) {\n            time += 2;\n            int apples = dfs(g, adj.get(i), n, hasApple, visited);\n            if(apples == 0) time -= 2;\n            count += apples;\n        }\n        return count;\n    }\n    public int minTime(int n, int[][] edges, List<Boolean> hasApple) {\n        int m = edges.length;\n        time = 0;\n        List<List<Integer>> g = new ArrayList<>();\n        for(int i = 0; i < n; i++) g.add(new ArrayList<>());\n        for(int i = 0; i < m; i++) {\n            g.get(edges[i][0]).add(edges[i][1]);\n            g.get(edges[i][1]).add(edges[i][0]);\n        }\n        boolean[] visited = new boolean[n];\n        int totalApples = dfs(g, 0, n, hasApple, visited);\n        return time;\n    }\n}
[]