tricky implementation ( beats 95%)
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```cpp []\n#define ll long long\n#define ll long long\nclass Solution {\npublic:\n    vector<ll> ans;\n    \n    vector<ll> solve(int par , int gpar , vector<vector<int>> &tree , vector<int> &cost){\n        vector<ll> res;\n        for(auto child : tree[par]){\n            if(child == gpar) continue;\n            vector<ll> temp = solve(child , par , tree , cost);\n            for(auto i : temp) res.push_back(i);\n        }\n        res.push_back(cost[par]);\n        sort(res.begin() , res.end());\n        ll a1 = 0;\n        if(res.size() < 3){\n            a1 = 1;\n            ans[par] = 1;\n            return res;\n        }\n        else{\n            int n = res.size();\n            a1 = max(res[0] * res[1] * res[n -1] , res[n - 1] * res[n - 2] * res[n - 3]);\n            if(a1 < 0) a1 = 0;\n            ans[par] = a1;\n            if(n <= 5) return res;\n            else return {res[0] , res[1] , res[n -3] , res[n - 2] , res[n - 1]};\n        }\n    }\n    vector<long long> placedCoins(vector<vector<int>>& edges, vector<int>& cost) {\n        int n = edges.size() + 1;\n        ans.resize(n);\n        vector<vector<int>> tree(n);\n        for(auto i  :edges){\n            int u = i[0] , v = i[1];\n            tree[u].push_back(v);\n            tree[v].push_back(u);           \n        }\n        solve(0 , -1 , tree , cost);\n        return ans;\n    }\n};\n```
['Depth-First Search', 'Sorting', 'C++']