[Java] Bubble up the value of nodes O(nlogn)
Understand the problem\n1. Check if the destination node has an apple\n2. If it has an apple add (+2) to get to the node. Save this value in the map as from to 
**Understand the problem**\n1. Check if the destination node has an apple\n2. If it has an apple add (+2) to get to the node. Save this value in the map as from to bubble it up.\n3. If there is any node connected to the bubbled up values you can add that value to it\n4. Eventually the value will be bubbled up to the root\n\n```\nclass Solution {\n    public int minTime(int n, int[][] edges, List<Boolean> hasApple) {\n        \n        // Sort in descending order to bubble up the number on the path\n        Arrays.sort(edges, new Comparator<int []>() {\n           public int compare(int e1[], int e2[]) {\n               return e2[0] - e1[0];\n           }\n        });\n\n        Map<Integer, Integer> timeAtNode = new HashMap<>();\n        for (int edge[]:edges) {\n            int from = edge[0];\n            int to = edge[1];\n            int time = 0;\n            // If this node has an apple or this node has some value collected from its children path\n            if (hasApple.get(to) || timeAtNode.containsKey(to) && timeAtNode.get(to) > 0) {\n                time = time + 2;\n            }\n            // bubble up the value where there is an edge connecting to me\n            if ( timeAtNode.containsKey(to) && timeAtNode.get(to) > 0) {\n                time = time + timeAtNode.get(to);\n            }\n            // Add this value to bubble it up\n            timeAtNode.put(from, timeAtNode.getOrDefault(from, 0) + time);\n        }\n        return timeAtNode.get(0);\n    }\n}\n```
[]