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!!!求帮助,快!/*一直停留在WA和RUNTIME ERROR中,求帮助!知道的地下评论一下!*/ #include<cstdio> #include<cstring> const int N=110; int t,n,m,x,y,z,p,v,min,ans,num,ans1; int f[N]; int pre1[N]; int map[N][N]; bool flag[N]; bool ql; int pre[N]; struct edge1{ int x,y,z; }; edge1 edge[N]; int main(){ freopen("test2.0.in","r",stdin); //freopen("poj1679.out","w",stdout); scanf("%d",&t); while(t--){ scanf("%d%d",&n,&m); if(m==0){ printf("0\n"); } memset(map,0,sizeof map); for(int i=1;i<=m;++i){ scanf("%d%d%d",&x,&y,&z); map[x][y]=z; map[y][x]=z; } for(int i=0;i<=n;++i)f[i]=1000000; f[1]=0; memset(flag,true,sizeof flag); memset(pre,-1,sizeof pre); for(int i=1;i<=n-1;++i){ min=1000000; for(int j=1;j<=n;++j){ if(f[j]<min and flag[j]){ min=f[j]; v=j; } } flag[v]=false; for(int j=1;j<=n;++j){ if(map[v][j]>0 and flag[j] and map[v][j]<f[j]){ f[j]=map[v][j]; pre[j]=v; } } } num=0; for(int i=2;i<=n;++i){ ++num; edge[num].x=pre[i]; edge[num].y=i; edge[num].z=map[pre[i]][i]; } ans=0; for(int i=1;i<=n;++i) ans+=f[i]; for(int ii=1;ii<=n-1;++ii){ map[edge[ii].x][edge[ii].y]=0; for(int i=0;i<=n;++i)f[i]=1000000; f[1]=0; memset(flag,true,sizeof flag); memset(pre1,-1,sizeof pre); ans1=0; for(int i=1;i<=n-1;++i){ min=1000000;v=-1; for(int j=1;j<=n;++j){ if(f[j]<min and flag[j]){ min=f[j]; v=j; } } if(v==-1){ printf("%d\n",ans);return 0; } ql=true; flag[v]=false; for(int j=1;j<=n;++j){ if(map[v][j]>0 and flag[j] and map[v][j]<f[j]){ f[j]=map[v][j]; pre1[j]=v; } } } for(int i=1;i<=n;++i) ans1+=f[i]; if(ans1==ans){ printf("Not Unique!\n"); ql=false; break; }else{ map[edge[ii].x][edge[ii].y]=edge[ii].z; } } if(!ql)continue; 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