标签:
#include<iostream> #include<stdio.h> #include<math.h> #include<string.h> #include<algorithm> #define INF 0xfffffff #define N 1100 using namespace std; int n,m,dist[N],vis[N]; int maps[N][N]; void Init() { int i,j; memset(vis,0,sizeof(vis)); for(i=0;i<=n;i++) { dist[i]=0; for(j=0;j<=n;j++) { maps[i][j]=0; } } } void Dij(int Start,int End) { int Max,index,i,j; dist[Start] = INF; for(i = 1; i <= n; i++) { index=-1; Max=0; for(j = 1; j <= n; j++) { if(vis[j] == 0 && Max < dist[j]) { Max = dist[j]; index = j; } } if(index == -1)break; vis[index] = 1; for(j = 1; j <= n; j++) { if(vis[j] == 0&&dist[j] < min(dist[index],maps[index][j])) dist[j] = min(dist[index],maps[index][j]); } } } int main() { int T,t=1,a,b,c; scanf("%d",&T); while(T--) { scanf("%d%d",&n,&m); Init(); while(m--) { scanf("%d%d%d",&a,&b,&c); maps[a][b] = maps[b][a] = max(maps[a][b],c); } Dij(1,n); printf("Scenario #%d:\n%d\n\n",t++,dist[n]); } return 0; }
Heavy Transportation---poj1797
标签:
原文地址:http://www.cnblogs.com/zhengguiping--9876/p/4667731.html