Java || Easy Approach with Explanation || Preorder || Postorder || DFS
\nclass Solution \n{\n    public int minTime (int n, int[][] edges, List<Boolean> hasApple) \n    {\n        ArrayList<ArrayList<Integer>> adjacencyList= new Ar
```\nclass Solution \n{\n    public int minTime (int n, int[][] edges, List<Boolean> hasApple) \n    {\n        ArrayList<ArrayList<Integer>> adjacencyList= new ArrayList<>();\n        \n        for (int i= 0; i< n; i++)\n            adjacencyList.add(new ArrayList<>());//allocating the space for the vertex to store their adjacent vertex \n        \n        //Creating the adjacency list from the edge list \n        for (int []edge: edges)\n        {\n            int u= edge[0];\n            int v= edge[1];\n            \n            //undirected graph \n            adjacencyList.get(u).add(v);   \n            adjacencyList.get(v).add(u);    \n        }\n        boolean visited[]= new boolean[n];//boolean visited array, so that we dont visit the same vertex again \n        return dfs(adjacencyList ,visited, hasApple, 0);//recursing down in depth of the tree and calculating the time while in postorder, like topological sort(iterative) \n    }\n    public int dfs (ArrayList<ArrayList<Integer>> adjacencyList, boolean visited[], List<Boolean> hasApple, int source)\n    {//preorder marking visited -> recursing in deapth -> postorder time calculation //Bottom Up Approach \n        visited[source]= true;//marking the current node as visisted \n        \n        int totalTime= 0;//time possible \n        for (int vertex: adjacencyList.get(source)){//recursing down in deapth \n            if(visited[vertex] == false)//only visiting the unvisited node \n                totalTime+= dfs(adjacencyList, visited, hasApple, vertex);//calculating the time while we are backtracking  \n        }\n        \n        if (source != 0 && (hasApple.get(source) || totalTime > 0))//we are not considering the starting vertex because we are calculating the total time from bottom to top //case-1) when the total time is greater than 0 then we would include that path(intution: apple already exists previously in the path)//case-2)we are considering the vertex with apple for total time calculation(intution: considering the edge)\n           totalTime+= 2;//adding two because of 1)moving forward(arriving) 2)moving backward(returning) \n        return totalTime;//returning the total time to tell the current time status to the parent \n    }\n}//Please do Upvote, it helps a lot \n```
['Depth-First Search', 'Graph', 'Java']