{"trustable":false,"sections":[{"title":"Input","value":{"format":"MD","content":"套利是指利用货币汇率的差异,将一种货币的一个单位转换为同一货币的多个单位。例如,假设 $1$ 美元买 $0.5$ 英镑,$1$ 英镑买 $10.0$ 法国法郎,$1$ 法国法郎买 $0.21$ 美元。然后,通过兑换货币,聪明的交易者可以从 $1$ 美元开始,购买 $0.5 \\times 10.0 \\times 0.21 \u003d 1.05$ 美元,获得 $5\\%$ 的利润。\n\n您的工作是编写一个程序,以货币汇率列表作为输入,然后确定是否可能进行套利。"}},{"title":"Output","value":{"format":"MD","content":"输入将包含一个或多个测试用例。每个测试用例的第一行有一个整数 $n$ ($1\\le n\\le30$),表示不同货币的数量。接下来的 $n$ 行每一行都包含一种货币的名称。名称中不会出现空格。下一行包含一个整数 $m$,表示接下来的表的长度。最后的 $m$ 行分别包含源货币的名称 $c_i$、表示从 $c_i$ 到 $c_j$ 的汇率的实数 $r_{i,j}$ 和目标货币的名称 $c_j$。没有出现在表格中的交易是不可能的。\n\n测试用例通过空行彼此分开。对于 $n$,输入以 `0` 结束。"}},{"title":"Sample","value":{"format":"MD","content":"\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\u003e3\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\u003eCase 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"}}]}