Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
ft ~~~优先队列BFS一直TLE。。。到底错哪儿了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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator