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 767401875 at 2009-08-14 14:26:12 on Problem 3268
#include <stdio.h>
#include <memory.h>
#define MAXN 1000
int used[MAXN + 10], map[MAXN + 10][MAXN + 10], L[MAXN + 10], result[MAXN + 10];
int n, m, x;
void res()
{
	int i, j, t, used[MAXN + 10][MAXN + 10];
	memset (used, 0, sizeof(used));
	for (i = 1; i <= n; i++)
	 for (j = 1; j <= n; j++)
	   if(!used[i][j])
 	   {
	    t = map[i][j];
	 	map[i][j] = map[j][i];
	 	map[j][i] = t;
	 	used[i][j] = used[j][i] = 1;
 	   }
}	 
void Dijkstra()
{
	int i, j, min, minj;
	memset (used, 0, sizeof(used));
	memset (L, 110, sizeof(L));
	L[x] = 0;
    for (i = 1; i <= n; i++)
    {
    	if(i == x)
    	continue;
    	min = 110;
		for (j = 1; j <= n; j++)
		if(L[j] < min&&!used[j])
		{
		  min = L[j];
		  minj = j;
		}
		used[minj] = 1;
		for (j = 1; j <= n; j++)
		if(!used[j]&&L[minj] + map[minj][j] < L[j])
		L[j] = map[minj][j] + L[minj];
    }
    for (i = 1; i <= n; i++)
    result[i] += L[i];
}
int main()
{
	int i, j, begin, end, t, max;
	memset (map, 110, sizeof(map));
	memset (result, 0, sizeof(result));
	scanf ("%d%d%d", &n, &m, &x);
	for (i = 1; i <= m; i++)
	{
		scanf ("%d%d%d", &begin, &end, &t);
		map[begin][end] = t;
	}
	Dijkstra();
	res();
	Dijkstra();
	max = 0;
	for (i = 1; i <= n; i++)
	if(max < result[i])
	max = result[i];
	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