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

Re:为何RE!!!!!!!!!!!!!

Posted by iamzky at 2013-11-07 08:37:24 on Problem 1258
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:
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