分类: C/C++
2008-03-08 01:26:37
#include#include char ch[35][35],st[35],en[35]; double c[35][35],dis; int m,n; int find(char *d) { int i; for(i=1;i<=n;i++) if(strcmp(d,ch[i])==0)return i; return -1; } int main() { int f,i,j,k,cas=1,b,e; while(scanf("%d",&n)&&n) { for(i=1;i<=n;i++) {scanf("%s",ch[i]); for(j=1;j<=n;j++) c[i][j]=-1.0; } scanf("%d",&m); //memset(c,0,sizeof(c)); for(i=1;i<=m;i++) { scanf("%s%lf%s",st,&dis,en); b=find(st);e=find(en); c[b][e]=dis; //if(b==e) c[b][e]=1.0; } //floyd f=0; for(k=1;k<=n;k++) { for(i=1;i<=n;i++) for(j=1;j<=n;j++) if(c[i][k]>0&&c[k][j]>0&&c[i][k]*c[k][j]>c[i][j]) {c[i][j]=c[i][k]*c[k][j];} for(i=1;i<=n;i++) if(c[i][i]>1.0){f=1;break;} } printf("Case %d: ",cas++); if(f)printf("Yes\n"); else printf("No\n"); } }