Open-Pit Mining
Time limit1sMemory limit512 MB
Given blocks with values and digging costs plus precedence constraints, find the maximum profit subset closed under the dig-before relation.
- Level
Hard8 of 10
- Topics
- Graph, Minimum spanning tree, Greedy, Union-find
- Solved
- No attempts yet
Problem
Open-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 has a value , and digging it out of the land costs . Some blocks bury other blocks. If block and block obstruct block , then block and block must both be dug up before block 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.
Input
The first line contains an integer (), the number of blocks. The blocks are numbered 1 through .
The next lines describe the blocks. The -th of those lines describes block and starts with the value and the cost of block (). A third integer then gives the number of blocks that block obstructs (). After it come the labels of those blocks, integers separated by spaces. The labels are distinct, lie between 1 and , and never include .
Some digging order gets every block out. The sum of over all blocks is at most 500.
Output
Print a single integer, the maximum profit ACM can achieve from the given piece of land.