Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
把min 设成0x7FFFFFFF,WA,改为0x7FFFFF,AC 为甚么啊,#include<stdio.h> #include<stdlib.h> #include<string.h> int f[1010][1010]; int g[1010][1010]; int D[1010],final[1010],a[1010]; int n,m,x; int dijkstra(int x,int f[][1010]) { int i,j,k,min,ans; for(i=1;i<=n;i++) { D[i]=f[x][i]; final[i]=0; } final[x]=1; for(i=2;i<=n;i++) { min=0x7FFFFFFF; for(j=1;j<=n;j++) if(D[j]<min&&!final[j]) { k=j; min=D[j]; } final[k]=1; for(j=1;j<=n;j++) if(!final[j]&&(min+f[k][j]<D[j])) D[j]=min+f[k][j]; } return 0; } int main() { int i,j,k,s,t,v,ans; while(scanf("%d%d%d",&n,&m,&x)!=EOF) { for(i=0;i<=n;i++) for(j=0;j<=n;j++) g[i][j]=f[i][j]=0x7FFFFFFF; for(i=0;i<m;i++) {scanf("%d %d %d",&s,&t,&v); if(f[s][t]>v) f[s][t]=v; if(g[t][s]>v) g[t][s]=v; } memset(D,0,sizeof(D)); for(i=1;i<=n;i++) f[i][i]=g[i][i]=0; dijkstra(x,f); for(i=1;i<=n;i++) a[i]=D[i]; memset(D,0,sizeof(D)); dijkstra(x,g); for(i=1;i<=n;i++) a[i]+=D[i]; ans=0; for(i=1;i<=n;i++) if(a[i]>ans) ans=a[i]; printf("%d\n",ans); } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator