CODEFORCES:103E(二分图匹配&最大流)

博客介绍了如何利用二分图匹配和最大流解决CODEFORCES 103E问题,即在满足集合并集势等于集合个数的条件下,找出最小价格的集合组合。通过建立二分图、最大权闭合子图和最小割的模型,转换为最大流问题,并提供了匈牙利算法和Ford-Fulkerson算法的求解思路。
摘要由CSDN通过智能技术生成

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

<

评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值