[C++] priority queue
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    pair<int, pair<vector<int>, vector<int>>> dfs(int node, int parent, vector<int>& cost, unordered_map<int, vector<int>>& adj, vector<long long>& ans) {\n        // return {subtree size, top 3 costs}\n        // max product: --+ or +++\n\n        int subtree = 1;\n        priority_queue<int, vector<int>, greater<>> greatest; // top 3 costs\n        priority_queue<int> smallest; // smallest 2 enough!\n        greatest.push(cost[node]);\n        smallest.push(cost[node]);\n\n        for( int neighbor : adj[node] ) {\n            if( neighbor != parent ) {\n                auto [sub_size, vs] = dfs(neighbor, node, cost, adj, ans);\n                auto [top3, small3] = vs;\n                subtree += sub_size;\n\n                for( int c : top3 ) {\n                    greatest.push(c);\n                    if( greatest.size() > 3 )\n                        greatest.pop();\n                }\n\n                for( int c : small3 ) {\n                    smallest.push(c);\n                    if( smallest.size() > 2 )\n                        smallest.pop();\n                }\n            }\n        }\n\n        vector<int> top;\n        while( !greatest.empty() ) {\n            top.push_back(greatest.top());\n            greatest.pop();\n        }\n        vector<int> small;\n        while( !smallest.empty() ) {\n            small.push_back(smallest.top());\n            smallest.pop();\n        }\n\n        if( subtree < 3 )\n            ans[node] = 1;\n        else \n            ans[node] = max(0LL, max(\n                (long long)top[0] * top[1] * top[2],\n                (long long)small[1] * small[0] * top[2] \n            ));\n\n        return {subtree, {top, small}};\n    }\n\npublic:\n    vector<long long> placedCoins(vector<vector<int>>& edges, vector<int>& cost) {\n        unordered_map<int, vector<int>> adj;\n        for( auto& e : edges ) {\n            adj[e[0]].push_back(e[1]);\n            adj[e[1]].push_back(e[0]);\n        }\n\n        vector<long long> ans(cost.size());\n        dfs(0, -1, cost, adj, ans);\n\n        return ans;\n    }\n};\n```
['C++']