{"trustable":true,"prependHtml":"\u003cscript\u003e\n window.katexOptions \u003d {\n delimiters: [\n {left: \u0027\\\\(\u0027, right: \u0027\\\\)\u0027, display: false},\n ]\n };\n\u003c/script\u003e\n","sections":[{"title":"","value":{"format":"MD","content":"Arbitrage is the use of discrepancies in currency exchange rates to transform one unit of a currency into more than one unit of the same currency. For example, suppose that 1 US Dollar buys 0.5 British pound, 1 British pound buys 10.0 French francs, and 1 French franc buys 0.21 US dollar. Then, by converting currencies, a clever trader can start with 1 US dollar and buy 0.5 \\* 10.0 \\* 0.21 \u003d 1.05 US dollars, making a profit of 5 percent.\n\nYour job is to write a program that takes a list of currency exchange rates as input and then determines whether arbitrage is possible or not.\n\n### Input Specification\n\nThe input file will contain one or more test cases. Om the first line of each test case there is an integer \u003cI\u003en\u003c/I\u003e (1\u003c\u003d\u003cI\u003en\u003c/I\u003e\u003c\u003d30), representing the number of different currencies. The next \u003cI\u003en\u003c/I\u003e lines each contain the name of one currency. Within a name no spaces will appear. The next line contains one integer \u003cI\u003em\u003c/I\u003e, representing the length of the table to follow. The last \u003cI\u003em\u003c/I\u003e lines each contain the name \u003cI\u003ec\u003cSUB\u003ei\u003c/SUB\u003e\u003c/I\u003e of a source currency, a real number \u003cI\u003er\u003cSUB\u003eij\u003c/SUB\u003e\u003c/I\u003e which represents the exchange rate from \u003cI\u003ec\u003cSUB\u003ei\u003c/SUB\u003e\u003c/I\u003e to \u003cI\u003ec\u003cSUB\u003ej\u003c/SUB\u003e\u003c/I\u003e and a name \u003cI\u003ec\u003cSUB\u003ej\u003c/SUB\u003e\u003c/I\u003e of the destination currency. Exchanges which do not appear in the table are impossible.\n\nTest cases are separated from each other by a blank line. Input is terminated by a value of zero (0) for \u003cI\u003en\u003c/I\u003e.\n\n### Output Specification\n\nFor each test case, print one line telling whether arbitrage is possible or not in the format \"Case \u003cI\u003ecase\u003c/I\u003e: Yes\" respectively \"Case \u003cI\u003ecase\u003c/I\u003e: No\".\n\n### Sample:\n\n\u003ctable class\u003d\u0027vjudge_sample\u0027\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003eInput\u003c/th\u003e\n \u003cth\u003eOutput\u003c/th\u003e\n \u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003e\n3\nUSDollar\nBritishPound\nFrenchFranc\n3\nUSDollar 0.5 BritishPound\nBritishPound 10.0 FrenchFranc\nFrenchFranc 0.21 USDollar\n\n3\nUSDollar\nBritishPound\nFrenchFranc\n6\nUSDollar 0.5 BritishPound\nUSDollar 4.9 FrenchFranc\nBritishPound 10.0 FrenchFranc\nBritishPound 1.99 USDollar\nFrenchFranc 0.09 BritishPound\nFrenchFranc 0.19 USDollar\n\n0\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e\nCase 1: Yes\nCase 2: No\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n\n"}}]}