We are given some graph nodes and every node has three things:
Cost to include this node
Money we get while we include this node.
It's parent who should be included if this node is included ( It's may possible to not having a parent for some node )
Now I have to choose some nodes out of these such that total cost of selected nodes shouldn't exceed M and we should be able to earn maximum possible money.
How to solve this problem?