|
||||||||||
SendingTime Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 331 Accepted Submission(s): 9 Problem Description 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 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. Output 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. Sample Input
Sample Output
Author DYGG Source | ||||||||||
|