Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 10450 Accepted Submission(s): 3694
Safe(P) = s(e1)*s(e2)…*s(ek) e1,e2,ek是P 上的边
1 #include<iostream> 2 #include<cstring> 3 #include<cstdio> 4 #include<map> 5 #define ll __int64 6 using namespace std; 7 int n; 8 double mp[1005][1005]; 9 double ans[1005][1005]; 10 int s,e; 11 int m; 12 void floyd() 13 { 14 memset(ans,0,sizeof(ans)); 15 for(int i=1; i<=n; i++) 16 for(int j=1; j<=n; j++) 17 for(int k=1; k<=n; k++) 18 { 19 if(mp[j][i]*mp[i][k]>mp[j][k]) 20 mp[j][k]=mp[j][i]*mp[i][k]; 21 } 22 } 23 int main() 24 { 25 while(scanf("%d",&n)!=EOF) 26 { 27 memset(mp,0,sizeof(mp)); 28 for(int i=1; i<=n; i++) 29 for(int j=1; j<=n; j++) 30 scanf("%lf",&mp[i][j]); 31 floyd(); 32 scanf("%d",&m); 33 for(int i=1; i<=m; i++) 34 { 35 scanf("%d %d",&s,&e); 36 if(mp[s][e]>=1e-4) 37 printf("%.3f\n",mp[s][e]); 38 else 39 printf("What a pity!\n"); 40 } 41 } 42 return 0; 43 }