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 ~~WA??why??哪位大侠看一下啊~~急死了#include<iostream> using namespace std; int main() { int i,j,n,c; int a[30][30],k; char v,r='A'; for(i=0;i<30;i++) for(j=0;j<30;j++) { if(i==j) a[i][j]=0; else a[i][j]=200; } while(cin>>n&&n!=0) { for(i=0;i<n-1;i++) { cin>>v>>k; for(j=0;j<k;j++) { cin>>r>>c; a[r-'A'][i]=a[i][r-'A']=c; } } int opt[30],max=0,min,vertex,sum; short int flag[30]; sum=0; for(i=0;i<n;i++) opt[i]=a[0][i]; flag[0]=1; for(i=1;i<n;i++) flag[i]=0; for(i=1;i<n;i++){ min=100001; for(j=0;j<n;j++){ if(!flag[j]&&min>opt[j]){ min=opt[j]; vertex=j; } } flag[vertex]=1; sum+=min; for(j=0;j<n;j++){ if(!flag[j]) opt[j]=opt[j]>a[j][vertex]?a[j][vertex]:opt[j]; } } cout<<sum<<endl; } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator