当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

1586:Sending

题目描述
It's said that "Writing a love-letter is mush easier than sending it out". After writing the love-letter with the help of ALM, Gardon is now planing how to send it to his Angel.
Er......In fact Gardon is too shy to send it directly. - -b So we needs to find some one to help him ...As the old saying goes "You should pay to get something". Gardon must spend some money to buy gifts to someone who helps him. And there are also rules to give somebody gifts:
1. Some helpers need a number of gift.
2. If you ask A to send some gifts to B, besides the quantity of gifts A ordered, you must also give the same quantity of gifts to A as many as gifts you ask A to give B.

For example, there are four people, Angel, Bred, Cici, Dennis. Bred orderd two gifts, Cici and Dennis asked only one for themselves, and the way to send the letter is: Gardon==>Dennis==>Cici==>Bred==>Angel, so Gardon will buy Cici totally three gifts(one orded,the other two are paid for Cici sending gifts to Bred), and buy Dennis totally six gifts (one orded, the other two are paid for Dennis sending gifts to Cici). So totally Gardon need to buy eleven gifts - Bred two, Cici three, and Dennis six.

Now, giving every body's name, the quantity of gifts he/she ordered, and all person he/she knows (One can ask anybody who he/she knows), could you tell Gardon how many gifts he need to buy?
输入解释
Input starts with a integer T, and followed by T test cases.
In the begining of each case there is a integer N, which means how many person in the record.
Then N lines following, and each of them starts with a name. After their name, there are two integers V and C. V means the quantity of gifts he/she ordered, and following C names shows every person he/she knows.
You should know that all name is a word of at most 20 lowercases with a uppercase letter leading, and you can assume that there is no more than 1000 records in each test case. No one knows more than ten of others.
Everyone in the list will have a record except Angel.You'll always have a record of Gardon.
输出解释
For each test case inputed, please tell whether Gardon can send the letter out:
1. If he cannot, print "Please do it yourself!"
2. If he can, but should pay more than or equal with 1,000,000,000 gifts, print "It cost too many!"
3. Otherwise, print the gifts he needs to buy.
输入样例
1
4
Bred 2 1 Angel
Cici 1 1 Bred
Dennis 1 1 Cici
Gardon 0 2 Dennis Angel
输出样例
Case 1: 11
来自杭电HDUOJ的附加信息
Author DYGG
Recommend linle

该题目是Virtual Judge题目,来自 杭电HDUOJ

源链接: HDU-1586

最后修改于 2020-10-25T22:46:14+00:00 由爬虫自动更新

共提交 149

通过率 57.72%
时间上限 内存上限
1000/1000MS(Java/Others) 32768/32768K(Java/Others)