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

高手看看我程序有啥问题,为什么总wa阿,不就是求最短路问题吗?

Posted by hotrhino at 2008-04-10 02:56:18 on Problem 2394
#include<stdio.h>
int main(){
	int ver[505][505];
	int MAX=1000000;
	int f,p,cow,timeS;
	scanf("%d%d%d%d",&f,&p,&cow,&timeS);
	int i,j,k;
	for (i=0; i<=f; i++)
		for (j=0; j<=f;j++)
			ver[i][j]=MAX;
	int tmp;
	for (k=0; k<p; k++){
			scanf("%d%d",&i,&j);
			scanf("%d",&tmp);
			if (tmp<ver[i][j]){
				ver[j][i]=tmp;
				ver[i][j]=tmp;
			}
	};
	for (k=1; k<=f;k++)
		for (i=1;i<=f; i++)
			for (j=1;j<=f; j++)
				if (ver[i][k]+ver[k][j]<ver[i][j])
					ver[i][j]=ver[i][k]+ver[k][j];
	for (k=1; k<=f; k++)
		ver[k][k]=MAX;
	int cowstr[500];
	int count=0;
	for (i=1; i<=cow; i++){
		scanf("%d",&cowstr[i]);
		if (ver[cowstr[i]][1]<=timeS)
			count++;
	}
	printf("%d\n",count);
	for (i=1; i<=cow; i++)
		if (ver[cowstr[i]][1]<=timeS)
			printf("%d\n",i);
	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