#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;
int n;
double g[35][35];
char dict[35][100];
int find( char s[100] )
{
for( int i= 1; i<= n; ++i )
if( strcmp( dict[i], s )== 0 ) return i;
}
int main()
{
int test= 1;
while( scanf("%d",&n), n )
{
for( int i= 1; i<= n; ++i )
scanf("%s", dict[i] );
int m; scanf("%d", &m );
memset( g, 0, sizeof(g) );
for( int i= 0; i< m; ++i )
{
char s1[100], s2[100];
double v;
scanf("%s %lf %s", s1, &v, s2 );
g[ find(s1) ][ find(s2) ]= v;
}
for( int k= 1; k<= n; k++ )
for( int i= 1; i<= n; i++ )
for( int j= 1; j<= n; j++ )
{
double temp= g[i][k]* g[k][j];
if( temp> g[i][j] ) g[i][j]= temp;
}
bool ok= false;
for( int i= 1; i<= n; i++ )
if( g[i][i]> 1 ) {
ok= true; break; }
if( ok ) printf("Case %d: Yes\n", test++ );
else printf("Case %d: No\n", test++ );
}
return 0;
}
posted on 2008-11-07 14:08
Darren 阅读(208)
评论(0) 编辑 收藏 引用