Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

prim ~~WA??why??哪位大侠看一下啊~~急死了

Posted by ding59 at 2008-10-27 21:32:50 on Problem 1251
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator