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

STL给力!用priority_queue优化的dijkstra能过。

Posted by fanhqme at 2011-04-24 15:44:19 on Problem 1511
void dijkstra(){
	priority_queue<pair<long long,int>,vector<pair<long long,int> >,greater<pair<long long,int> > >PQ;
	for (int i=0;i<N;i++)dist[i]=~0uLL>>2;
	dist[0]=0;
	PQ.push(make_pair(dist[0],0));
	while (!PQ.empty()){
		long long d=PQ.top().first;
		int a=PQ.top().second;
		PQ.pop();
		if (d!=dist[a])continue;
		for (edge *p=E[a];p;p=p->next)
			if (dist[p->e]>d+p->c)
				PQ.push(make_pair(dist[p->e]=d+p->c,p->e));
	}
}

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