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

代码!!!

Posted by chenxuan123456789 at 2012-07-28 10:07:04 on Problem 2421
#include <stdio.h>
#include <string.h>
#define M 100+10
#define INF 999999
int road[M][M];
int city[M];
int s[M];
int main()
{
	int n,m,i,j,k,sum,rec,max;
	scanf("%d",&n);
		for(i=1;i<=n;i++)
	{
	 getchar();
	 for(j=1;j<=n;j++)
	  scanf("%d",&road[i][j]);
	}
	scanf("%d",&m);
	for(k=1;k<=m;k++)
	{
	 scanf("%d %d",&i,&j);
	 road[i][j]=0;
	 road[j][i]=0;
	}
	memset(s,0,sizeof(s));
	for(i=1;i<=n;i++)
	city[i]=road[1][i];
	sum=0;
	s[1]=1;
	for(i=1;i<n;i++)
	{
		max=INF;
		for(j=1;j<=n;j++)
		if(!s[j]&&city[j]<max)
		{
			max=city[j];
			rec=j;
		}
		sum+=city[rec];
		s[rec]=1;
		for(j=1;j<=n;j++)
			if(!s[j]&&road[rec][j]<city[j])
				city[j]=road[rec][j];
	}
	printf("%d\n",sum);
	return 1;
}


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