[Python3] SortedList
\nfrom sortedcontainers import SortedList\n\nclass Solution:\n    def placedCoins(self, edges: List[List[int]], cost: List[int]) -> List[int]:\n        n = len(
```\nfrom sortedcontainers import SortedList\n\nclass Solution:\n    def placedCoins(self, edges: List[List[int]], cost: List[int]) -> List[int]:\n        n = len(edges) + 1\n        tree = [[] for _ in range(n)]\n        for u, v in edges: \n            tree[u].append(v)\n            tree[v].append(u)\n        ans = [1]*n \n        vals = [SortedList() for _ in range(n)]\n        \n        def fn(u, p): \n            """Return """\n            vals[u].add(cost[u])\n            for v in tree[u]: \n                if v != p:\n                    fn(v, u)\n                    for x in vals[v]: vals[u].add(x)\n            while len(vals[u]) > 5: vals[u].pop(2)\n            if len(vals[u]) < 3: ans[u] = 1\n            else: \n                m = max(vals[u][0]*vals[u][1], vals[u][-3]*vals[u][-2]) * vals[u][-1]\n                ans[u] = max(0, m)\n        \n        fn(0, -1)\n        return ans \n```
['Python3']