EZ Python3
Code\npython3 []\nclass Solution:\n    def placedCoins(self, edges: List[List[int]], cost: List[int]) -> List[int]:\n        node_to_nodes = _create_node_to_nod
# Code\n```python3 []\nclass Solution:\n    def placedCoins(self, edges: List[List[int]], cost: List[int]) -> List[int]:\n        node_to_nodes = _create_node_to_nodes(edges)\n\n        return _MaxCoinsCalculator.calculate(node_to_nodes, cost)\n\ndef _create_node_to_nodes(edges):\n    node_to_nodes = collections.defaultdict(list)\n\n    for node_1, node_2 in edges:\n        node_to_nodes[node_1].append(node_2)\n        node_to_nodes[node_2].append(node_1)\n\n    return node_to_nodes\n\nclass _MaxCoinsCalculator:\n    @staticmethod\n    def calculate(node_to_nodes, cost):\n        calculator = _MaxCoinsCalculator(node_to_nodes, cost)\n        calculator.__calculate_relevant_costs(0, None)\n\n        return calculator.__node_to_coins\n\n    def __init__(self, node_to_nodes, cost):\n        self.__cost = cost\n        self.__node_to_nodes = node_to_nodes\n        self.__node_to_coins = [0] * len(node_to_nodes)\n\n    def __calculate_relevant_costs(self, node, previous_node):\n        relevant_costs = [self.__cost[node]]\n        tree_size = 1\n\n        for child in self.__node_to_nodes.get(node, tuple()):\n            if child == previous_node:\n                continue\n\n            relevant_costs_child, tree_size_child = self.__calculate_relevant_costs(child, node)\n            tree_size += tree_size_child\n            relevant_costs.extend(relevant_costs_child)\n            relevant_costs.sort()\n\n            if len(relevant_costs) > 6:\n                relevant_costs = relevant_costs[:3] + relevant_costs[-3:]\n    \n        if tree_size <= 2:\n            self.__node_to_coins[node] = 1\n        else:\n            self.__node_to_coins[node] = max(\n                relevant_costs[-1] * relevant_costs[-2] * relevant_costs[-3],\n                relevant_costs[0] * relevant_costs[-2] * relevant_costs[-1],\n                relevant_costs[0] * relevant_costs[1] * relevant_costs[-1],\n                0,\n            )\n\n        return (relevant_costs, tree_size,)\n\n```
['Python3']