标签:des style blog http color os io strong
Time Limit: 3000MS | Memory Limit: 30000K | |
Total Submissions: 20364 | Accepted: 5401 |
Description
Input
Output
Sample Input
1 3 3 1 2 3 1 3 4 2 3 5
Sample Output
Scenario #1: 4
Source
1 #include<cstdio> 2 #include<cstring> 3 #include<stdlib.h> 4 #include<algorithm> 5 using namespace std; 6 const int MAXN=1000+10; 7 const int INF=0x3f3f3f3f; 8 int dis[MAXN],vis[MAXN],w[MAXN][MAXN]; 9 int n,m; 10 void dijkstra() 11 { 12 memset(vis,0,sizeof(vis)); 13 for(int i=1;i<=n;i++) 14 dis[i]=w[1][i]; 15 for(int i=1;i<=n;i++) 16 { 17 int x,temp=-1; 18 for(int j=1;j<=n;j++) 19 { 20 if(!vis[j]&&dis[j]>temp) 21 { 22 temp=dis[j]; 23 x=j; 24 } 25 } 26 vis[x]=1; 27 for(int j=1;j<=n;j++) 28 if(!vis[j]&&dis[j]<min(dis[x],w[x][j])) 29 dis[j]=min(dis[x],w[x][j]); 30 } 31 } 32 int main() 33 { 34 //freopen("in.txt","r",stdin); 35 int kase,cnt=0; 36 scanf("%d",&kase); 37 while(kase--) 38 { 39 for(int i=1;i<=n;i++) 40 for(int j=1;j<=n;j++) 41 w[i][j]=0; 42 scanf("%d %d",&n,&m); 43 for(int i=1;i<=m;i++) 44 { 45 int star,en,val; 46 scanf("%d %d %d",&star,&en,&val); 47 w[star][en]=w[en][star]=val; 48 } 49 dijkstra(); 50 printf("Scenario #%d:\n",++cnt); 51 printf("%d\n\n",dis[n]); 52 } 53 return 0; 54 }
POJ 1797 Heavy Transportation (最短路变形),布布扣,bubuko.com
POJ 1797 Heavy Transportation (最短路变形)
标签:des style blog http color os io strong
原文地址:http://www.cnblogs.com/clliff/p/3921394.html