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 |
为什么wa了?#include<stdio.h> #include<string.h> #include<stdlib.h> #include<algorithm> using namespace std; const int mxn = 505; const int mxm = 50005; const int inf = 100000; int d[mxn],s[mxn],e[mxn][mxn],n,m; void dijkstra() { int i,j; for(i=0;i<n;i++) { s[i]=0;d[i]=e[0][i]; } s[0]=1;d[0]=0; for(i=1;i<n;i++) { int u=0,min=inf; for(j=0;j<n;j++) if(!s[j] && d[j]<min) min=d[u=j]; s[u]=1;d[u]=min; for(j=0;j<n;j++) if(!s[j] && d[u]+e[u][j]<d[j]) d[j]=d[u]+e[u][j]; } } int main() { int kase=1; while(1) { scanf("%d%d",&n,&m); if(n==0 && m==0) break; for(int i=0;i<n;i++) for(int j=0;j<n;j++) e[i][j]=inf; for(int i=0;i<n;i++) e[i][i]=0; int u,v,w; while(m--) { scanf("%d%d%d",&u,&v,&w); e[--u][--v]=e[v][u]=w; } dijkstra(); int mm1=0,mm2=0; for(int i=0;i<n;i++) { if(mm1<d[i]){ mm1=d[i];u=i; } } for(int i=0;i<n;i++) for(int j=0;j<n;j++) { int tt=d[i]+d[j]+e[i][j]; if(tt>inf) continue; if(mm2<tt){ mm2=tt;v=i;w=j; } } printf("System #%d\nThe last domino falls after ",kase++); if(2*mm1>=mm2) printf("%d.0 seconds, at key domino %d.\n\n",mm1,u+1); else { printf("%d",mm2/2); if(mm2%2) printf(".5"); else printf(".0"); printf(" seconds, between key dominoes %d and %d.\n\n",v+1,w+1); } } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator