Banner Home Page Web Contests Problems Ranklist Status Statistics

Bribing FIPA

Time Limit : 4000/2000ms (Java/Other)   Memory Limit : 131072/65536K (Java/Other)
Total Submission(s) : 0   Accepted Submission(s) : 0
Problem Description

There is going to be a voting at FIPA (F¨¦d¨¦ration Internationale de Programmation Association) to determine the host of the next IPWC (International Programming World Cup). Benjamin Bennett, the delegation of Diamondland to FIPA, is trying to seek other delegation's support for a vote in favor of hosting IWPC in Diamondland. Ben is trying to buy the votes by diamond gifts. He has figured out the voting price of each and every country. However, he knows that there is no need to diamond-bribe every country, since there are small poor countries that take vote orders from their respected superpowers. So, if you bribe a country, you have gained the vote of any other country under its domination (both directly and via other countries domination). For example, if C is under domination of B, and B is under domination of A, one may get the vote of all three countries just by bribing A. Note that no country is under domination of more than one country, and the domination relationship makes no cycle. You are to help him, against a big diamond, by writing a program to find out the minimum number of diamonds needed such that at least m countries vote in favor of Diamondland. Since Diamondland is a candidate, it stands out of the voting process.

 

Input
<div><p>The input consists of multiple test cases. Each test case starts with a line containing two integers <i>n</i> (1 ≤ <i>n</i> ≤ 200) and <i>m</i> (0 ≤ <i>m</i> ≤ <i>n</i>) which are the number of countries participating in the voting process, and the number of votes Diamondland needs. The next <i>n</i> lines, each describing one country, are of the following form:</p><p><i>CountryName</i> <i>DiamondCount</i> <i>DCName</i><sub>1</sub> <i>DCName</i><sub>1</sub> ...</p><p><i>CountryName</i>, the name of the country, is a string of at least one and at most 100 letters and <i>DiamondCount</i> is a positive integer which is the number of diamonds needed to get the vote of that country and all of the countries that their names come in the list <i>DCName</i><sub>1</sub> <i>DCName</i><sub>1</sub> ... which means they are under direct domination of that country. Note that it is possible that some countries do not have any other country under domination. The end of the input is marked by a single line containing a single # character.</p>
 

Output
<p>For each test case, write a single line containing a number showing the minimum number of diamonds needed to gain the vote of at least m countries.</p>
 

Sample Input
3 2 Aland 10 Boland 20 Aland Coland 15 #
 

Sample Output
20
 

Source
PKU
 

Statistic | Submit | Back