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

ft ~~~优先队列BFS一直TLE。。。到底错哪儿了

Posted by lpms26086 at 2010-08-09 11:38:33 on Problem 3377
int bfs()
{
	NODE t_node,node;
	int i,j,k,u,v;
	__int64 tmp;
	/* clear the queue */
	while(!que.empty())
		que.pop();
	SET_NODE(t_node,start,0);
	que.push(t_node);
	relax[start] = 0;
	/* while loop */
	while(!que.empty())
	{
		node = que.top();
		que.pop();
		u = node.v;
		if(node.val > relax[node.v])
			continue;
		if(u == end)
		{
			ans = node.val;
			return 0;
		}
		visit[u] = true;
		for(i = net[node.v]; i != -1; i = edge[i].next)
		{
			v = edge[i].v;
			if(visit[v])
				continue;
			tmp = node.val + edge[i].val;
			if((relax[v] == -1||relax[v] > tmp))
			{
				relax[v] = tmp;
				SET_NODE(t_node,v,tmp);
				que.push(t_node);
			}
		}
	}
	ans = -1;
	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