标签:
3 1 0.5 0.5 0.5 1 0.4 0.5 0.4 1 3 1 2 2 3 1 3
0.500 0.400 0.500
HDU 2007-Spring Programming Contest - Warm Up (1)
#include<stdio.h> #include<string.h> #include<algorithm> using namespace std; #define M 1005 #define inf 100000 int vis[M]; double path[M][M],dis[M]; int n,m; void dij(int s){//求最长路 memset(vis,0,sizeof(vis)); int i,j,k; double temp; for(i=1;i<=n;i++) dis[i]=path[s][i]; vis[s]=1; for(i=1;i<n;i++){ k=i; temp=-1; for(j=1;j<=n;j++){ if(!vis[j] && temp<dis[j]){ temp=dis[j]; k=j; } } vis[k]=1; for(j=1;j<=n;j++){ if(!vis[j]) dis[j]=max(dis[j],dis[k]*path[k][j]); } } } int main(){ while(~scanf("%d",&n)){ int i,j,a,b; for(i=1;i<=n;i++) for(j=1;j<=n;j++) scanf("%lf",&path[i][j]); scanf("%d",&m); while(m--){ scanf("%d%d",&a,&b); dij(a); if(dis[b]==0)//题中的不连通是0,不是inf,,,fuck printf("What a pity!\n"); else printf("%.3lf\n",dis[b]); } } return 0; }
hdu 1596 find the safest road(最长路)
标签:
原文地址:http://blog.csdn.net/ling_du/article/details/47779835