Python DFS + Heap approach
Code\n\nclass Solution:\n\n    def __init__(self):\n        self.coins = []\n\n    def findMaxNodes(self, currPosHeap, currNegHeap, newPosHeap, newNegHeap):\n  
# Code\n```\nclass Solution:\n\n    def __init__(self):\n        self.coins = []\n\n    def findMaxNodes(self, currPosHeap, currNegHeap, newPosHeap, newNegHeap):\n        while(newPosHeap):\n            currElem = heapq.heappop(newPosHeap)\n            heapq.heappush(currPosHeap, currElem)\n            if(len(currPosHeap)>3):\n                heapq.heappop(currPosHeap)\n        while(newNegHeap):\n            currElem = heapq.heappop(newNegHeap)\n            heapq.heappush(currNegHeap, currElem)\n            if(len(currNegHeap)>3):\n                heapq.heappop(currNegHeap)\n        return currPosHeap, currNegHeap \n\n    def dfs(self, currNode, graph, cost, visited):\n        visited.add(currNode)\n        currNegHeap, currPosHeap = [],[]\n        if currNode==None:\n            return currNegHeap, currPosHeap\n        if cost[currNode] < 0:\n            heapq.heappush(currNegHeap, abs(cost[currNode]))\n        else:\n            heapq.heappush(currPosHeap, cost[currNode])\n\n        if currNode in graph:\n            for neigh in graph[currNode]:\n                if neigh not in visited:\n                    newPosHeap, newNegHeap = self.dfs(neigh, graph, cost, visited)\n                    currPosHeap, currNegHeap  = self.findMaxNodes(currPosHeap, currNegHeap, \n                                                            newPosHeap, newNegHeap)\n           \n        maxProduct = 1\n        if len(currNegHeap) + len(currPosHeap) < 3:\n            self.coins[currNode] = 1\n        else:\n            prodVal = [i*(-1) for i in currNegHeap] + currPosHeap\n            prodVal.sort()\n            maxProduct = max(prodVal[-1]*prodVal[-2]*prodVal[-3], \n                            prodVal[0]*prodVal[1]*prodVal[-1])\n            if maxProduct>0:\n                self.coins[currNode] =  maxProduct\n            else:\n                self.coins[currNode] =  0\n            \n        # print(currNode, currPosHeap, currNegHeap, self.coins)\n        return currPosHeap, currNegHeap \n\n    def placedCoins(self, edges: List[List[int]], cost: List[int]) -> List[int]:\n        graph = {}\n        size = len(cost)\n        self.coins = [1 for i in range(size)]\n\n        for e in edges:\n            v1 = e[0]\n            v2 = e[1]\n\n            if v1 not in graph:\n                graph[v1] = []\n            \n            if v2 not in graph:\n                graph[v2] = []\n            \n            graph[v1].append(v2)\n            graph[v2].append(v1)\n        visited = set()\n        self.dfs(0, graph, cost, visited)\n        return self.coins\n```
['Python3']