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 chenxuan19920611 at 2012-07-27 10:41:00 on Problem 2421
#include "stdio.h"
#include "string.h"
#define INF 999999
#define N 105
int road[N][N];
int s[N],city[N];
int main()
{
	int n,i,j,m,temp,total,rec,min,s1,e1;
	scanf("%d",&n);
	memset(road,INF,sizeof(road));
	for(i=1;i<=n;i++)
	{
		getchar();
		for(j=1;j<=n;j++)
		scanf("%d",&road[i][j]);
	}
	memset(s,0,sizeof(s));
	total=0;
	s[1]=1;
	scanf("%d",&m);
	for(i=1;i<=m;i++)
	{
	 scanf("%d %d",&s1,&e1);
     road[s1][e1]=0;
	 road[e1][s1]=0;
	}
	for(i=1;i<=n;i++)
	city[i]=road[1][i];
	for(i=1;i<n;i++)
	{
		min=INF;
		rec=-1;
		for(j=1;j<=n;j++)
			if(!s[j]&&city[j]<min)
			{
				min=city[j];
				rec=j;
			}
		s[rec]=1;
		total+=min;
		for(j=1;j<=n;j++)
		if(road[rec][j]<city[j]&&!s[j])
		city[j]=road[rec][j];
	}
	printf("%d\n",total);
	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