| ||||||||||
| 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 | |||||||||
STL给力!用priority_queue优化的dijkstra能过。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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator