1 ///Dijkstra优先队列模板
 2 struct Node
 3 {
 4     int x,d;
 5     Node(int a,int b){x=a;d=b;}
 6     bool operator < (const Node & a) const
 7     {
 8         return d>a.d;
 9     }
10 };
11 vector<Node>g[mx];
12 int ds[mx];
13 int n,m;
14 
15 void dijk()
16 {
17     priority_queue<Node>q;
18     q.push(Node(1,0));
19     while (!q.empty())
20     {
21         Node N=q.top();q.pop();
22         for (int i=0;i<g[N.x].size();i++)
23         {
24             Node y=g[N.x][i];
25             if (ds[y.x]>y.d+N.d)
26             {
27                 ds[y.x]=y.d+N.d;
28                 q.push(Node(y.x,ds[y.x]));
29             }
30         }
31     }
32 }

 

posted on 2016-07-29 20:21  pb2016  阅读(198)  评论(0编辑  收藏  举报