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

为什么我的bellman_ford 对所有的边松弛操作时要执行|V|次,|V|-1次就WA?

Posted by 1905220268 at 2009-07-21 20:17:34 on Problem 1364
bool bellman_ford()
{
	bool flag;
	int i,j;
	memset(dis,0,sizeof(dis));
	for(i=0;i<n;i++)				//奇怪,这个循环要执行n次才ac,n-1次就wa 
	{
		flag=false;
		for(j=1;j<=m;j++)
		{
			if(dis[e[j].u]+e[j].w<dis[e[j].v])
			{
				dis[e[j].v]=dis[e[j].u]+e[j].w;
				flag=true;
			}
		}
		if(!flag)	
			return false;
	}
	for(i=1;i<=m;i++)
	{
		if(dis[e[i].u]+e[i].w<dis[e[i].v])
			return true;
	}
	return false;
}

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