Shortest paths from one source on a graph with non-negative edge weights.
Dijkstra's algorithm finds the shortest path from a starting node to every other node in a weighted graph — as long as no edge has a negative weight. It works greedily: always finalize the closest unfinished node next.
Keep a tentative shortest distance to every node (∞ at first, 0 for the source). Repeatedly pick the unvisited node with the smallest tentative distance, lock it in as final, and *relax* its neighbours — if going through this node is cheaper, update their distance.
dist[source] = 0, everything else ∞.u with the smallest dist (a priority queue makes this fast).u visited — its distance is now final.v: if dist[u] + weight(u,v) < dist[v], update dist[v].