Given a DAG $G=(V,E)$ and a weights function on the vertices $w:V \to \mathbb{R}$, suggest an algorithm that computes for every $v \in V$ the sum of the weights of vertices that are reachable from it.
My idea is to use topological sort on the graph and then start from the end to the start, and for each vertex $v \in V$ set the sum to $S(v)=w(v)+\sum_{(v, u) \in E} S(u)$.
But this can cause counting some vertices multiple times, which I am not sure how to fix while still solving the problem in linear time.