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 |
Re:为何RE!!!!!!!!!!!!!In Reply To:为何RE!!!!!!!!!!!!! Posted by:iamzky at 2013-11-07 08:29:35 #include<cstdio> #include<cstring> #include<iostream> using namespace std; int a[101][101],i,j,n,minn[101]; bool b[101]; int prim(int s) { int i,j,k,ans=0; memset(minn,0x7f,sizeof(minn)); minn[s]=0; memset(b,true,sizeof(b)); for(i=1;i<=n;i++) { k=0; for(j=1;j<=n;j++) if(b[j]&&(minn[j]<minn[k])) k=j; b[k]=false; for(j=1;j<=n;j++) if((a[k][j]<minn[j])&&b[j]&&a[k][j]!=0) minn[j]=a[k][j]; } for(i=1;i<=n;i++) ans+=minn[i]; return ans; } int main() { while(scanf("%d",&n)!=EOF) { memset(a,0,sizeof(a)); for(i=1;i<=n;i++) for(j=1;j<=n;j++) scanf("%d",&a[i][j]); int ans; ans=prim(1); 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