Just a runnable solution
\n\nimpl Solution {\n    const MAX_NODES: usize = 3;\n\n    pub fn placed_coins(edges: Vec<Vec<i32>>, cost: Vec<i32>) -> Vec<i64> {\n        let mut ans = vec![
\n```\nimpl Solution {\n    const MAX_NODES: usize = 3;\n\n    pub fn placed_coins(edges: Vec<Vec<i32>>, cost: Vec<i32>) -> Vec<i64> {\n        let mut ans = vec![0; cost.len()];\n        let mut t = vec![vec![]; cost.len()];\n        for e in edges {\n            t[e[0] as usize].push(e[1] as usize);\n            t[e[1] as usize].push(e[0] as usize);\n        }\n        Solution::dfs(&t, &cost, 0, -1, &mut ans);\n        ans\n    }\n\n    fn dfs(t: &Vec<Vec<usize>>, cost: &Vec<i32>, root: usize, par: i32, ans: &mut Vec<i64>) -> Vec<i64> {\n        let mut useful_cost = vec![cost[root] as i64];\n        for &n in &t[root] {\n            if n as i32 == par {\n                continue;\n            }\n            let v = Solution::dfs(t, cost, n, root as i32, ans);\n            for &e in &v {\n                useful_cost.push(e);\n            }\n        }\n        useful_cost.sort_unstable_by(|a, b| b.cmp(a));\n        let sz = useful_cost.len();\n        if sz < Solution::MAX_NODES {\n            ans[root] = 1;\n            return useful_cost;\n        }\n        if useful_cost[1] * useful_cost[2] > useful_cost[sz - 1] * useful_cost[sz - 2] {\n            ans[root] = useful_cost[0] * useful_cost[1] * useful_cost[2];\n        } else {\n            ans[root] = useful_cost[0] * useful_cost[sz - 1] * useful_cost[sz - 2];\n        }\n        if ans[root] < 0 {\n            ans[root] = 0;\n        }\n        if sz <= 5 {\n            return useful_cost;\n        }\n        vec![\n            useful_cost[0],\n            useful_cost[1],\n            useful_cost[2],\n            useful_cost[sz - 2],\n            useful_cost[sz - 1],\n        ]\n    }\n}\n\n```
['Rust']