Skip to content

Instantly share code, notes, and snippets.

@Chillee
Last active April 14, 2019 19:24
Show Gist options
  • Save Chillee/3c176b08aced575c603fcf273d347c1c to your computer and use it in GitHub Desktop.
Save Chillee/3c176b08aced575c603fcf273d347c1c to your computer and use it in GitHub Desktop.
Dijkstra
vector<array<int, 2>> adj[MAXN];
int dist[MAXN];
void dijkstra(int start) {
fill(begin(dist), end(dist), INF);
priority_queue<array<int, 2>, vector<array<int,2>>, greater<array<int, 2>>> pq;
pq.push({0, start});
while (!pq.empty()) {
auto t = pq.top();
pq.pop();
if (dist[t[1]] <= t[0])
continue;
dist[t[1]] = t[0];
for (auto i : adj[t[1]])
pq.push({t[0] + i[0], i[1]});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment