[Java] Explained - Graph + DFS
\nstatic HashMap<Integer, LinkedList<Integer>> g;\nstatic List<Boolean> hasApple;\n\n  public static int minTime(int n, int[][] edges, List<Boolean> _hasApple) 
```\nstatic HashMap<Integer, LinkedList<Integer>> g;\nstatic List<Boolean> hasApple;\n\n  public static int minTime(int n, int[][] edges, List<Boolean> _hasApple) {\n    g = new HashMap<>();\n    hasApple = _hasApple;\n    for (int[] e : edges) {\n\t  //Build Graph using edges\n      g.putIfAbsent(e[0], new LinkedList<>());\n      g.get(e[0]).add(e[1]);\n    }\n    return dfs(0);\n  } \n  \n  private static int dfs(int pos) {\n    int childCount = 0;\n    if (g.containsKey(pos))//check if its leafNode\n\t\tfor (int child : g.get(pos))//if not leafnode go for child nodes\n\t\t\tchildCount += dfs(child);\n    if (childCount == 0) {\n\t//childCount will be 0 if leaf node\n\t//if has apple return 2 \n      return hasApple.get(pos) ? 2 : 0;\n    } else {\n\t//otherwise return childern status\n      return childCount + (pos == 0 ? 0 : 2);\n    }\n  }\n```
[]