标签:
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 10714 Accepted Submission(s): 3789
#include <stdio.h> #include <algorithm> #include <string.h> #include <math.h> #include <queue> using namespace std; const int N = 1005; double graph[N][N]; double dis[N]; double low[N]; bool vis[N]; int n; void dijkstra(int s){ memset(vis,false,sizeof(vis)); for(int i=1;i<=n;i++){ low[i] = graph[s][i]; } vis[s] = true; for(int i=1;i<n;i++){ double Max = 0; for(int j=1;j<=n;j++){ if(!vis[j]&&Max<low[j]){ s = j; Max = low[j]; } } vis[s] = true; for(int j=1;j<=n;j++){ if(low[j]<low[s]*graph[s][j]&&!vis[j]){ low[j] = low[s]*graph[s][j]; } } } } int main() { while(scanf("%d",&n)!=EOF){ for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++){ scanf("%lf",&graph[i][j]); } } int m; scanf("%d",&m); while(m--){ int s,t; scanf("%d%d",&s,&t); dijkstra(s); if(low[t]==0) printf("What a pity!\n"); else printf("%.3lf\n",low[t]); } } return 0; }
标签:
原文地址:http://www.cnblogs.com/liyinggang/p/5489899.html