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 madongtest at 2006-09-26 12:56:56 on Problem 2394
#include<stdio.h>
#define SIZE 505
#define MAX 10000000

int map[SIZE][SIZE],len[SIZE],n;
void dij(int s)
{
	int i,k;
	for(i = 1; i <= n; i++)
		len[i] = map[s][i];
	//map[s][s] = 0; <-----------  如果加上这句,就RE。为什么?(map[i][i]=0表示节点i已被访问)
	len[s] = 0;
	for(k = 1; k <= n; k++){
		int min = MAX,e;
		for(i = 1; i <= n; i++)
			if(map[i][i] && min > len[i]){
				e = i;
				min = len[i];
			}
		map[e][e] = 0;
		if(min == MAX)
			return;
		for(i = 1; i <= n; i++)
			if(map[i][i] && len[i] > len[e] + map[i][e])
				len[i] = len[e]+map[i][e];
	}
}
int main()
{
	int p,c,m,i,j,x,y,z,out[110];
	scanf("%d%d%d%d",&n,&p,&c,&m);
	for(i = 1; i <= n; i++)
		for(j = 1; j <= n; j++)
			map[i][j] = MAX;
	for(i = 0; i < p; i++){
		scanf("%d%d%d",&x,&y,&z);
		if(map[x][y] > z)
			map[x][y] = map[y][x] = z;
	}
	dij(1);
	y = 0;
	for(i = 1; i <= c; i++){
		scanf("%d",&x);
		if(len[x] <= m)
			out[y++] = i;
	}
	printf("%d\n",y);
	for(i = 0; i < y; i++)
		printf("%d\n",out[i]);
	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