1 #include <iostream>
2 #include <stdio.h>
3 #include <string.h>
4 #include <cstring>
5 #include<map>
6 using namespace std;
7
8 map<string,int>name;
9 const int INF = 1000000;
10 const int MAXSIZE = 1005;
11 const int MAXN = 30;
12 double g[MAXN][MAXN];
13
14 //dis[][]记录任意两点间的最短路径,初始的dis[][]记录直接路径
15 void floyed(double dis[][MAXN],int n){//节点从1~n编号
16 int i,j,k;
17 for(k = 1; k <= n; k++)
18 for(i = 1; i <= n; i++)
19 for(j = 1; j <= n; j++)
20 if(dis[i][j] < dis[i][k] * dis[k][j])
21 dis[i][j] = dis[i][k] * dis[k][j];
22 }
23 int main(){
24 int n,i,m,j;
25 string str1,str2;
26 double r;
27 int iCase = 0;
28 while(scanf("%d",&n),n){
29 iCase++;
30 for(i = 1; i <= n; i++){
31 cin>>str1;
32 name[str1] = i;
33 }
34 for(i = 1; i <= n; i++)
35 for(j = 1; j <= n; j++){
36 if(i == j) g[i][j] = 1;
37 else g[i][j] = 0;
38 }
39 scanf("%d",&m);
40 while(m--){
41 cin>>str1>>r>>str2;
42 g[name[str1]][name[str2]] = r;
43 }
44
45 floyed(g,n);
46
47 bool flag = false;
48 for(i = 1; i <= n; i++){
49 if(g[i][i] > 1){
50 flag = true;
51 break;
52 }
53 }
54 if(flag) printf("Case %d: Yes\n",iCase);
55 else printf("Case %d: No\n",iCase);
56 }
57 return 0;
58 }
HDOJ 1217 Floyed Template,码迷,mamicode.com
时间: 2024-10-25 12:29:56