Mistake: forgetting to exclude child when computing up[v]. This makes up[v] include down[v], which you then add again in the final answer. Result: double-counting nodes in 's subtree. Mistake: using the wrong formula for edge weights. If edges have weights , you need down[u] + w(u,v) * size[v], not down[u] + size[v].
The weight multiplies the count. Mistake: not handling the root separately. The root has no parent, so up[root] = 0. Make sure your code initializes this correctly and does not try to access the parent of the root.