Simple DFS | Two Vector for Storing Positive and Negative Value
\nclass Solution {\npublic:\n    vector<vector<int>> solve(int node,vector<vector<int>> &adj,vector<long long> &ans,vector<int> &vis,vector<int> &cost)\n    {\n
```\nclass Solution {\npublic:\n    vector<vector<int>> solve(int node,vector<vector<int>> &adj,vector<long long> &ans,vector<int> &vis,vector<int> &cost)\n    {\n        vis[node]=1;\n        vector<int> res1(3,INT_MIN);\n        vector<int> res2(3,INT_MAX);\n        \n        for(auto child:adj[node])\n        {\n            if(vis[child]==1)\n                continue;\n            \n            vector<vector<int>> tem=solve(child,adj,ans,vis,cost);\n            \n            vector<int> tem2(6);\n            \n            tem2[0]=tem[0][0];\n            tem2[1]=tem[0][1];\n            tem2[2]=tem[0][2];\n            tem2[3]=res1[0];\n            tem2[4]=res1[1];\n            tem2[5]=res1[2];\n            \n            vector<int> tem3(6);\n            \n            tem3[0]=tem[1][0];\n            tem3[1]=tem[1][1];\n            tem3[2]=tem[1][2];\n            tem3[3]=res2[0];\n            tem3[4]=res2[1];\n            tem3[5]=res2[2];\n            \n            \n            \n            \n            sort(tem2.rbegin(),tem2.rend());\n            sort(tem3.begin(),tem3.end());\n            \n            \n            res1[0]=tem2[0];\n            res1[1]=tem2[1];\n            res1[2]=tem2[2];\n            \n            res2[0]=tem3[0];\n            res2[1]=tem3[1];\n            res2[2]=tem3[2];\n        }\n        \n         vector<long long> tem2(4);\n        tem2[0]=res1[0];\n        tem2[1]=res1[1];\n        tem2[2]=res1[2];\n        tem2[3]=cost[node];\n           \n            \n            sort(tem2.rbegin(),tem2.rend());\n            \n            res1[0]=tem2[0];\n            res1[1]=tem2[1];\n            res1[2]=tem2[2];\n        \n         vector<long long> tem3(4);\n        tem3[0]=res2[0];\n        tem3[1]=res2[1];\n        tem3[2]=res2[2];\n        tem3[3]=cost[node];\n           \n            \n            sort(tem3.begin(),tem3.end());\n            \n            res2[0]=tem3[0];\n            res2[1]=tem3[1];\n            res2[2]=tem3[2];\n        \n        if(res1[2]==INT_MIN)\n        {\n            ans[node]=1;\n        }\n        else\n        {\n            long long a=res1[0];\n            long long b=res1[1];\n            long long c=res1[2];\n            \n            long long p=a*b*c;\n            long long a2=res2[0];\n            long long b2=res2[1];\n            long long c2=res2[2];\n            \n            long long q=a2*b2*a;\n            \n            p=max(p,q);\n            \n            if(p<=0)\n                ans[node]=0;\n            else\n                ans[node]=p;\n            \n            \n        }\n       \n        vector<vector<int>> res;\n        res.push_back(res1);\n        res.push_back(res2);\n        \n        return res;\n    }\n    vector<long long> placedCoins(vector<vector<int>>& edges, vector<int>& cost) {\n        int n=cost.size();\n        vector<vector<int>> adj(n);\n        \n        for(auto i:edges)\n        {\n            adj[i[0]].push_back(i[1]);\n            adj[i[1]].push_back(i[0]);\n        }\n        \n        \n        vector<long long> ans(n);\n        vector<int> vis(n,0);\n        solve(0,adj,ans,vis,cost);\n        \n        \n        \n        return ans;\n    }\n};\n```
['Depth-First Search', 'C', 'Sorting']