1 #include<iostream> 2 #include<stdio.h> 3 #include<string> 4 #include<algorithm> 5 #include<map> 6 #define MAXN 35 7 using namespace std; 8 9 map<string,int> coll; 10 map<string,int>::iterator pos1,pos2; 11 double _m[MAXN][MAXN]; 12 bool _wall[MAXN][MAXN]; 13 bool give_num(int n); 14 int main() 15 { 16 //freopen("acm.acm","r",stdin); 17 int n; 18 int edge; 19 int i; 20 int j; 21 int k; 22 double value; 23 string s; 24 string u; 25 string v; 26 int time = 0; 27 while(1) 28 { 29 //memset(_m,-1.0,sizeof(_m)); 30 cin>>n; 31 //getchar(); 32 if(!n) 33 break; 34 for(i = 0; i < n; ++i) 35 { 36 for(j = 0; j < n; ++ j) 37 { 38 _m[i][j] = -1.0; 39 } 40 } 41 42 cout<<"Case "<<++ time<<": "; 43 for(i = 0; i < n; ++ i) 44 { 45 cin>>s; 46 coll.insert(pair<string,int>(s,i)); 47 } 48 cin>>edge; 49 for(i = 0; i < edge; ++ i) 50 { 51 cin>>u>>value>>v; 52 pos1 = coll.find(u); 53 pos2 = coll.find(v); 54 // cout<<pos1->second<<"---------------"<<pos2->second<<endl; 55 _m[pos1->second][pos2->second] = value; 56 // _m[pos2->second][pos1->second] = value; 57 } 58 // for(i = 0; i < n; ++ i) 59 // { 60 // for(j = 0; j < n; ++ j) 61 // { 62 // cout<<_m[i][j]<<" "; 63 // } 64 // cout<<endl; 65 // } 66 if(give_num(n)) 67 cout<<"Yes"<<endl; 68 else 69 cout<<"No"<<endl; 70 coll.clear(); 71 } 72 } 73 74 bool give_num(int n) 75 { 76 int k; 77 int i; 78 int j; 79 double tem; 80 for(k = 0; k < n; ++ k) 81 { 82 for(i = 0; i < n; ++ i) 83 { 84 for(j = 0; j < n; ++ j) 85 { 86 // cout<<"00000000000000 "<<1.0/(_m[i][k] * _m[k][j])<<"--------"<<_m[j][i]<<endl; 87 if(_m[i][k] != -1.0 && _m[k][j] != -1.0 ) 88 { 89 if(_m[j][i] != -1.0) 90 { 91 if(( _m[i][k] * _m[k][j]) * _m[j][i] > 1.0) 92 { 93 // cout<<"00000000000000 "<<1.0/(_m[i][k] * _m[k][j])<<endl; 94 return true; 95 } 96 } 97 // else 98 // { 99 100 //} 101 if(_m[i][k] * _m[k][j] > _m[i][j]) 102 { 103 _m[i][j] = ( _m[i][k] * _m[k][j]); 104 } 105 } 106 } 107 } 108 } 109 return false; 110 }