Expands the closest unvisited node by total cost, guaranteeing the lowest-cost path when all weights are non-negative.
dist[start] ← 0pq ← [(0, start)]parent[start] ← nullwhile pq not empty:v ← extract_min(pq)for each neighbor u of v:newDist ← dist[v] + w(v,u)if newDist < dist[u]:dist[u] ← newDist; parent[u] ← v;parent[u] ← v; push pqif goal extracted: reconstruct path