WC '02 P3 - The Big Book of Recipes

View as PDF

Submit solution

Points: 10
Time limit: 1.0s
Memory limit: 16M

Problem type
Woburn Challenge 2002

So how is the monkeys' meeting going, you ask? Well, the Head-Monkey is quite big on food and whenever there's a meeting atop the Enchanted Tree, it is a necessity that dinner is served (pun intended). What the monkeys don't realize is that the Head-Monkey is not really a good cook. But then, how many army leaders are good cooks? The answer is, none. This time, the Head-Monkey has purchased a cookbook. The cookbook has a certain number of recipes, but any recipe may require an ingredient that must be prepared according to some other recipe! This is all quite confusing for the Head-Monkey. She wants you to tell her how much of each base ingredient she needs for her recipe.

Input Specification

The first line of input will contain a single integer, T (1 \le T \le 50), indicating the number of test cases.

The first line of each test case will contain N (1 \le N \le 20), the total number of ingredients to follow. For each ingredient, there follows a line with that ingredient's name - if the ingredient is a basic ingredient it will be in lowercase letters, if there is a recipe in terms of other ingredients for it, its name will be in capital letters.

For each non-basic ingredient, a recipe for one serving of that ingredient will follow (format: an integer k, 1 \le k \le 20, indicating the number of ingredients in that recipe, then a series of lines of the form [number of servings of ingredient required, space, ingredient required]).

Finally, there will be an ingredient name - you are to determine the amount of each basic ingredient required to make one serving of that ingredient.

The name of each ingredient will consist of either all lowercase or all uppercase English letters and possibly spaces. The name of each ingredient will have at most 50 characters.

Output Specification

A series of lines of the form [number of servings of ingredient required, space, ingredient required], containing only basic ingredients. Output them in the same order as they were listed in the input.

Each real value in your output should have an absolute or relative error from the reference solution of no more than 10^{-6}.

Sample Input

1
10
CHEESE
milk
SAMMICH
salt
turkey
ham
egg
vinegar
MAYO
bread
2
1.5 milk
0.25 salt
5
2.2 CHEESE
1 bread
1 turkey
1 ham
0.3 MAYO
3
0.2 egg
0.1 vinegar
0.1 salt
SAMMICH

Sample Output

3.3 milk
0.58 salt
1 turkey
1 ham
0.06 egg
0.03 vinegar
1 bread

Comments

There are no comments at the moment.