void dijkstra(int n, int x, std::vector<std::vector<int>> &p, std::vector<std::vector<int>> &w, std::vector<int> &dist) {
// n:点数 x:初始点 p,w:图 dist:距离
std::vector<bool> st(n + 1, false);
std::priority_queue<PII, std::vector<PII>, std::greater<PII>> h;
dist[x] = 0;
h.push({dist[x], x});
while (h.size()) {
int cur = h.top().second;
h.pop();
if (st[cur])
continue;
st[cur] = true;
for (int i = 0; i < p[cur].size(); i++) {
int tmp = p[cur][i], len = w[cur][i];
if (dist[tmp] > dist[cur] + len) {
dist[tmp] = dist[cur] + len;
h.push({dist[tmp], tmp});
}
}
}
return ;
}
标签:std,tmp,dist,cur,int,模版,扩展性,Dijkstra,vector
From: https://www.cnblogs.com/silverhand-dy/p/18446508