【模板】Dijkstra
C++版本:
Dijkstra
void dijkstra(int s) {
priority_queue<P, vector<P>, greater<P> >que;
fill(d + 1, d + V + 1, INF);
d[s] = 0;
que.push(make_pair(0, s));
while (!que.empty()) {
int u = que.top().second;
int di = que.top().first;
que.pop();
if (di > d[u])continue;
for (int i = head[u]; i; i = eg[i].next) {
int v = eg[i].to;
if (d[v] > d[u] + eg[i].cost) {
d[v] = d[u] + eg[i].cost;
que.push(make_pair(d[v], v));
}
}
}
}