首页 > 代码库 > find the safest road(弗洛伊德)

find the safest road(弗洛伊德)

http://acm.hdu.edu.cn/showproblem.php?pid=1596

#include <iostream>#include <stdio.h>#include <string.h>#include <stdlib.h>using namespace std;int n;int ss,ee;double map[1002][1002];void F(){    for(int k=1;k<=n;k++)    {        for(int j=1;j<=n;j++)        {            for(int i=1;i<=n;i++)            {                if(map[j][k]*map[k][i]>map[j][i])                    map[j][i]=map[j][k]*map[k][i];            }        }    }}int main(){    double t;    int Q;    int x,y;    while(scanf("%d",&n)!=EOF)    {        for(int i=1;i<=n;i++)        {            for(int j=1;j<=n;j++)            {                scanf("%lf",&t);                map[i][j]=t;            }        }        F();        scanf("%d",&Q);        while(Q--)        {            scanf("%d%d",&x,&y);            if(map[x][y]==0)                printf("What a pity!\n");            else printf("%.3lf\n",map[x][y]);        }    }    return 0;}