✅ C++ Intuitive Solution ✅ || Tree || DFS || 100% Faster ✅
Code\n\nclass Solution {\npublic:\n    vector<long long> placedCoins(vector<vector<int>>& edges, vector<int>& cost) {\n        // Declaration //\n        int n 
# Code\n```\nclass Solution {\npublic:\n    vector<long long> placedCoins(vector<vector<int>>& edges, vector<int>& cost) {\n        // Declaration //\n        int n = cost.size();\n        vector<int> graph[n];\n        vector<long long> coins(n);\n        // Building the Graph //\n        for(auto &edge : edges){\n            int u = edge[0], v = edge[1];\n            graph[u].push_back(v);\n            graph[v].push_back(u);\n        }\n        // Core Logic //         \n        DFS(graph, cost, coins, 0, -1);\n        return coins;\n    }\n    \n    vector<long long> DFS(vector<int> graph[], vector<int> &cost, vector<long long> &coins, int node, int parent){\n        int subtree = 1;\n        vector<long long> maxCosts = {cost[node]};\n        \n        for(auto &cn : graph[node]){\n            if( cn != parent ){\n                auto arr = DFS(graph, cost, coins, cn, node);\n                for(auto &val : arr){\n                    maxCosts.push_back(val);\n                }\n            }\n        }\n        sort(maxCosts.begin(), maxCosts.end(), greater<long long>());\n        if( maxCosts.size() < 3 ){\n            coins[node] = 1;\n        } else{\n            int size = maxCosts.size();\n            coins[node] = max((maxCosts[0]*maxCosts[1]*maxCosts[2]), (maxCosts[0]*maxCosts[size-1]*maxCosts[size-2]));\n            coins[node] = max((long long)0, coins[node]);\n            if( maxCosts.size() >= 5 ) {\n                return {maxCosts[0], maxCosts[1], maxCosts[2], maxCosts[size-2], maxCosts[size-1]};\n            }\n        }\n        return maxCosts;\n    }\n};\n```
['Divide and Conquer', 'Tree', 'Depth-First Search', 'C++']