http://acm.hdu.edu.cn/showproblem.php?pid=1596
1 #include <cstdio>
2 #include <cstring>
3 #include <algorithm>
4 #define maxn 1001
5 using namespace std;
6
7 double g[maxn][maxn];
8 int dis[maxn];
9 bool vis[maxn];
10 int n,a,b;
11
12 void floyd()
13 {
14 for(int k=1; k<=n; k++)
15 {
16 for(int i=1; i<=n; i++)
17 {
18 if(g[i][k]==0) continue;
19 for(int j=1; j<=n; j++)
20 {
21 if(g[i][j]<g[i][k]*g[k][j])
22 {
23 g[i][j]=g[i][k]*g[k][j];
24 }
25 }
26 }
27 }
28 }
29
30 int main()
31 {
32 while(scanf("%d",&n)!=EOF)
33 {
34 for(int i=1; i<=n; i++)
35 {
36 for(int j=1; j<=n; j++)
37 {
38 scanf("%lf",&g[i][j]);
39 }
40 }
41 floyd();
42 int m;
43 scanf("%d",&m);
44 for(int i=1; i<=m; i++)
45 {
46 scanf("%d%d",&a,&b);
47 if(g[a][b]!=0)
48 printf("%.3lf\n",g[a][b]);
49 else
50 printf("What a pity!\n");
51 }
52 }
53 return 0;
54 }
hdu 1596 find the safest road,布布扣,bubuko.com
时间: 2024-12-22 11:28:42