Bellman asks for the greatest ring.
Ask if the currency is in a settlement.
For example, if you get 1 yuan, if you get more than 1 yuan after the exchange, there will be a remittance.
MAP is more convenient.
# Include <cstdio> # include <cstring> # include <string> # include <queue> # include <algorithm> # include <queue> # include <map> # include <iostream> # define INF 0x7fffffffusing namespace STD; struct lx {int U, V; Double R ;}; int n, m; Map <string, int> STR; vector <lx> G; double d [31]; bool Bellman (INT start) {memset (D, 0, sizeof (d); D [start] = 1.0; For (INT I = 1; I <= N; I ++) {for (Int J = 0; j <G. size (); j ++) {int u = G [J]. u; int v = G [J]. v; double r = G [J]. r; d [v] = max (d [v], d [u] * r) ;}} if (d [start]> 1.0) return 1; return 0 ;} int main () {int COT = 1; while (scanf ("% d", & N), n) {Str. clear (); G. clear (); string S, S1, S2; For (INT I = 1; I <= N; I ++) {CIN> S; STR [s] = I;} CIN> m; Double R; For (INT I = 0; I <m; I ++) {CIN> S1> r> S2; lx now; now. U = STR [S1]; now. V = STR [s2]; now. R = r; G. push_back (now);} bool flag = 0; For (INT I = 1; I <= N; I ++) if (bellman (I) {flag = 1; break;} cout <"case" <cot ++ <":"; if (FLAG) puts ("yes "); else puts ("no ");}}