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 |
最简单的Prim,125msvoid prim() { int min=-INF; memset(dis,44,sizeof(dis)); dis[1]=0,used[1]=true; for (int r=ed[1];r;r=next[r]) dis[e[r]]=v[r],update[e[r]]=1; for (int i=1;i<n;i++) { int best=INF,r; for (int j=1;j<=n;j++) if (!used[j]&&dis[j]<best) best=dis[j],r=j; if (dis[r]>min) min=dis[r]; used[r]=true; for (int j=ed[r];j;j=next[j]) if (!used[e[j]]) if (dis[e[j]]>v[j]) dis[e[j]]=v[j],update[e[j]]=r; } printf("%d\n",min); printf("%d\n",n-1); for (int i=2;i<=n;i++) printf("%d %d\n",update[i],i); } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator