标签:
1 struct Node 2 { 3 int x,d; 4 Node(int a,int b){x=a;d=b;} 5 bool operator < (const Node & a) const 6 { 7 return d>a.d; 8 } 9 }; 10 vector<Node>g[mx]; 11 int ds[mx]; 12 int n,m; 13 14 void dijk() 15 { 16 priority_queue<Node>q; 17 q.push(Node(1,0)); 18 while (!q.empty()) 19 { 20 Node N=q.top();q.pop(); 21 for (int i=0;i<g[N.x].size();i++) 22 { 23 Node y=g[N.x][i]; 24 if (ds[y.x]>y.d+N.d) 25 { 26 ds[y.x]=y.d+N.d; 27 q.push(Node(y.x,ds[y.x])); 28 } 29 } 30 } 31 }
标签:
原文地址:http://www.cnblogs.com/pblr/p/5719610.html