post order travsersal of n-aray tree
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n\n    HashSet<Integer> visited = new HashSet();\n\n    public long[] placedCoins(int[][] edges, int[] cost) {\n        HashMap<Integer, List<Integer>> graph = new HashMap();\n        long[] result = new long[cost.length];\n        for(int[] edge: edges) {\n            List<Integer> list = graph.getOrDefault(edge[0], new LinkedList<Integer>());\n            list.add(edge[1]);\n            graph.put(edge[0], list);\n            list = graph.getOrDefault(edge[1], new LinkedList<Integer>());\n            list.add(edge[0]);\n            graph.put(edge[1], list);\n        }\n        count(graph, 0, result, cost);\n        return result;\n    }\n\n    public long[] count(HashMap<Integer, List<Integer>> graph, int start, long[] result, int[] cost) {\n        visited.add(start);\n        int ans = 1;\n        PriorityQueue<Long> pq = new PriorityQueue(Collections.reverseOrder());\n        PriorityQueue<Long> dq = new PriorityQueue();\n        pq.add(cost[start]*1l);\n        dq.add(cost[start]*1l);\n        for(int x: graph.get(start)){\n            if(!visited.contains(x)) {\n                long[] val = count(graph , x, result, cost);\n                ans += val[0];\n                for(int i=1;i<val.length;i++){\n                    pq.add(val[i]);\n                    dq.add(val[i]);\n                }\n            }\n        }\n        long a = pq.isEmpty()?0:pq.remove();\n        long b = pq.isEmpty()?0:pq.remove();\n        long c = pq.isEmpty()?0:pq.remove();\n        long d = dq.isEmpty()?0:dq.remove();\n        long e = dq.isEmpty()?0:dq.remove();\n        \n        if(ans < 3) {\n            result[start] = 1;\n        } else {\n            result[start] = Math.max(a*b*c*1l, a*d*e);\n        }\n        if(ans == 1) {\n            result[start] = 1;\n            visited.add(start);\n            return new long[]{1, cost[start], 0,  0, 0, 0};\n        }\n        return new long[]{ans,a,b,c,d,e};\n    }\n}\n```
['Java']