Given blocks with values and digging costs plus precedence constraints, find the maximum profit subset closed under the dig-before relation.
Hard8GraphMinimum spanning treeGreedyUnion-findNo attempts yetTime limit1sMemory limit512 MBOpen-pit mining takes rock or minerals out of the ground through a pit dug at the surface. Miners use it when a commercially useful deposit sits near the surface. The mining company ACM wants the largest profit it can get this way, and it has asked you for a program that reads a description of a piece of land and reports that profit.
One piece of land is modelled as a set of blocks of material. Block i has a value vi, and digging it out of the land costs ci. Some blocks bury other blocks. If block j and block k obstruct block i, then block j and block k must both be dug up before block i can be dug up. A block can be dug up only once no block obstructs it.
The profit of a set of dug blocks is the sum of their values minus the sum of their costs. ACM may stop digging at any point, and digging no block at all gives a profit of 0.
The first line contains an integer N (1≤N≤200), the number of blocks. The blocks are numbered 1 through N.
The next N lines describe the blocks. The i-th of those lines describes block i and starts with the value vi and the cost ci of block i (0≤vi,ci≤200). A third integer mi then gives the number of blocks that block i obstructs (0≤mi≤N−1). After it come the labels of those blocks, mi integers separated by spaces. The labels are distinct, lie between 1 and N, and never include i.
Some digging order gets every block out. The sum of mi over all blocks i is at most 500.
Print a single integer, the maximum profit ACM can achieve from the given piece of land.