Skip to content

Instantly share code, notes, and snippets.

@Hunachi
Created August 19, 2017 11:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Hunachi/a59412c8c0923e64518a3d64168a81ad to your computer and use it in GitHub Desktop.
Save Hunachi/a59412c8c0923e64518a3d64168a81ad to your computer and use it in GitHub Desktop.
struct{
void dijkstra(int s){
priority_queue<pii, vector<pii>, greater<pii> > que;
fill(d,d+V,INF);
d[s] = 0;
que.push(pii(0,s));
while(!que.empty()){
pii p = que.top(); que.pop();
int v = p.second;
if (d[v] < p.first) continue;
rep(i,0,G[v].size()){
edge e = G[v][i];
if(d[e.to] > d[v] + e.cost) {
d[e.to] = d[v] + e.cost;
que.push(pii(d[e.to], e.to));
}
}
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment