Do not write the Normal template, or need priority queue optimization of the Ang
1#include <stdio.h>//basic need for header files2#include <string.h>3#include <queue>4#include <algorithm>5#include <vector>6 using namespacestd;7typedef pair<int,int>PII;8 Const intinf=0x3f3f3f3f;9 Ten One structcmp{//Change priority queue to small Gan A BOOL operator() (PII a,pii b) { - returnA.first>B.first; - } the }; - - voidDij (intSintT) {//incoming starting point and arrival point - inti; +Priority_queue<pii,vector<pii>,cmp>Q; -Q.push (Make_pair (0, s)); +memset (dist,-1,sizeof(Dist)); Adist[s]=0; at while(!Q.empty ()) { -PII u=q.top (); - Q.pop (); - if(U.first>dist[u.second])Continue; - for(i=head[u.second];~i;i=Next[i]) { - intj=Point[i]; in if(dist[j]==-1|| dist[j]>u.first+Val[i]) { -dist[j]=u.first+Val[i]; to Q.push (Make_pair (dist[j],j)); + } - } the } *printf"%d\n", Dist[t]);//or remove the output or action in the main function $}
Shortest path--dijkstra+ Priority Queue Optimization Template