CODEFORCES 103E(二分图匹配&最大流)
参考:
最大权闭合子图(https://www.cnblogs.com/wuyiqi/archive/2012/03/12/2391960.html)
CF 103E 解题报告(https://www.cnblogs.com/xuesu/p/4418868.html)
1. 题目
E. Buying Sets
The Hexadecimal virus loves playing withnumber sets — intersecting them, uniting them. One beautiful day she wassurprised to find out that Scuzzy, her spherical pet cat, united all sets inone and ate the result! Something had to be done quickly and Hexadecimal rushedto the market.
The market has n sets of numbers on sale. The virus wants to buy thefollowing collection of sets: the number of sets in the collection should beexactly the same as the number of numbers in the union of all bought sets.Moreover, Hexadecimal wants to buy the cheapest suitable collection of set.
Yet nothing's so easy! As Mainframe is akingdom of pure rivalry markets, we know that the union of any k sets contains no less than kdistinct numbers (for every positive integer k).
Help the virus choose the suitablecollection of sets. The collection can be empty.
Input
The first line contains the onlynumber n (1 ≤ n ≤ 300) — the number of sets available in the market.
Next n linesdescribe the goods: first we are given mi (1 ≤ mi ≤ n)— the number of distinct numbers in the i-thset, then follow mi numbers — the set's elements. We know that theset's elements are distinct positive integers and they do not exceed n.
The last line contains n integers whose absolute values do not exceed 106 —the price of each set.
Output
Print a single number — the minimum pricethe virus will have to pay for such a collection of k sets that union of the collection's sets would haveexactly k distinct numbers.
Examples
input
Copy
3
1 1
2 2 3
1 3
10 20 -3
output
Copy
-3
input
<