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!!!!代码不长..麻烦高手帮我看看。谢了。。

Posted by newfolder at 2010-03-25 15:06:07 on Problem 2395
#include<stdio.h>
#include<string.h>
#include<math.h>
int a[2300][2300],d[2300],min,MAX=0;
int main()
{
	int n,m,v[2300],i,j,l,minj;
	scanf("%d%d",&n,&m);
	memset(a,-1,sizeof(a));
	while(m--)
	{
		scanf("%d%d%d",&i,&j,&l);
		if(l<a[i][j]||a[i][j]<0)
		{
			a[i][j]=l;
			a[j][i]=a[i][j];
		}
	}
	memset(v,0,sizeof(v));
	v[1]=1;
	for(i=1;i<=n;i++) d[i]=a[1][i];
	for(i=2;i<=n;i++)
	{
		min=1000000001;
		for(j=1;j<=n;j++)
		{
			if(!v[j]&&d[j]<min)
			{
				min=d[j];
				minj=j;
			}
		}
		v[minj]=1;
		if(min>MAX) MAX=min;
		for(j=1;j<=n;j++)
		{
			if(!v[j]&&a[minj][j]<d[j]) d[j]=a[minj][j];
		}
	}
	printf("%d\n",MAX);
	return 0;
}

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