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

完全没有考虑不连通的情况,也可以过。。。。。还0MS,太水了

Posted by bingshen at 2010-08-08 22:13:51 on Problem 1125
#include<stdio.h>
#include<string.h>
#include<algorithm>
#define inf 199999999

using namespace std;

int map[105][105];
int link[105];

void init()
{
	int i,j;
	for(i=0;i<105;i++)
		for(j=0;j<105;j++)
			map[i][j]=inf;
	for(i=0;i<105;i++)
	{
		map[i][0]=0;
		map[0][i]=0;
	}
	memset(link,0,sizeof(link));
}

int main()
{
	int i,j,k,t,n,w,l,min,num;
	while(scanf("%d",&t)!=EOF)
	{
		if(t==0)
			break;
		init();
		min=inf;
		for(k=1;k<=t;k++)
		{
			scanf("%d",&n);
			for(i=1;i<=n;i++)
			{
				scanf("%d%d",&l,&w);
				map[k][l]=w;
			}
		}
		for(k=1;k<=t;k++)
			for(i=1;i<=t;i++)
				for(j=1;j<=t;j++)
				{
					if(map[i][k]!=inf&&map[k][j]!=inf)
						if(map[i][j]==inf||map[i][j]>map[i][k]+map[k][j])
						{
							map[i][j]=map[i][k]+map[k][j];
						}
				}
		for(i=1;i<=t;i++)
			map[i][i]=0;
		for(i=1;i<=t;i++)
		{
			for(j=1;j<=t;j++)
			{
				if(i!=j)
					link[i]=link[i]+map[i][j];
			}
			if(link[i]<min)
			{
				min=link[i];
				num=i;
			}
		}
		sort(map[num],map[num]+t+1);
		printf("%d %d\n",num,map[num][t]);
	}
	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