新模板

 1 void dijkstra(int s) {
 2     std::priority_queue<Node> Q;
 3     memset(dis + 1, 0x3f, (n + 1) * sizeof(LL));
 4     dis[s] = 0;
 5     Q.push(Node(s, dis[s]));
 6     while(!Q.empty()) {
 7         while(!Q.empty() && dis[Q.top().x] != Q.top().dis) {
 8             Q.pop();
 9         }
10         if(Q.empty()) {
11             break;
12         }
13         int x = Q.top().x;
14         Q.pop();
15         for(int i = e[x]; i; i = edge[i].nex) {
16             int y = edge[i].v;
17             if(dis[y] > dis[x] + edge[i].len) {
18                 dis[y] = dis[x] + edge[i].len;
19                 Q.push(Node(y, dis[y]));
20             }
21         }
22     }
23     return;
24 }
Dijkstra

相关文章: