Sorry the title was no good. I am new to graph algorithms.
I'm stuck with a problem for several days. If all the nodes of a directed acyclic graph are weighted, while the weight can be negative, how can I find out a set for which the sum of the weights is maximum?
for example, we have a graph of 5 nodes-
- node 1 : weight 30, has a edges directed to node 4
- node 2 : weight 25, has edges directed to nodes 4,5
- node 3 : weight -65, no edges from it
- node 4 : weight -20, edge to node 5
- node 5 : weight 2, no edge from it
while finding out the maximum points, say, if node 1 is chosen, node 4 and as well as 5 must be chosen(as they are directly/indirectly adjacent from node 1).
so maximum point we can have is- (30-20+2)+(25)=37
for node 1 and descendant 4,5, and then for node 2(node 4,5 not considered anymore)
I hope I made my problem clear. Can anybody tell me how I can achieve this?