Java Solution
The approach here:\n    1) Build the graph backwards using a map\n     4 -> 1, 5 --> 1, 1 --> 0 etc\n    2) Get the nodes that has apples and put them inside a 
The approach here:\n    1) Build the graph backwards using a map\n     4 -> 1, 5 --> 1, 1 --> 0 etc\n    2) Get the nodes that has apples and put them inside a list\n    3) Loop through the nodes that has apples and call a method that will go back until it reaches 0, or if a node has already been visited. Checking if a node was visited will prevent counting it duplicate times.\n    \n\t\n\tpublic int minTime(int n, int[][] edges, List<Boolean> hasApple) {\n        Map<Integer,Integer> graph = new HashMap<>();\n        Set<Integer> visited = new HashSet<>();\n        List<Integer> ind = new ArrayList<>();\n        for(int[] e: edges){\n            graph.put(e[1],e[0]);\n        }\n        \n        for(int i = 0; i < n; i++){\n            if(hasApple.get(i) && i != 0) ind.add(i);\n        }\n        \n        int sol = 0;\n        for(int x: ind){\n            if(!visited.add(x)) continue;\n            sol += backwards(visited,x,graph);\n        }\n\n        return sol;  \n        \n    }\n    \n    private int backwards(Set<Integer> visited, int x, Map<Integer,Integer> graph){        \n        int count = 2;\n        \n        while(graph.get(x) != 0 && visited.add(graph.get(x)) ){\n            count += 2;\n            x = graph.get(x);\n            \n        }\n\n        return count;\n    }
[]