Algorithm ShortestPath(G, s):
    Input: A weighted graph G with nonnegative edge weights, and a distinguished
    vertex s of G.
    Output: The length of a shortest path from s to v for each vertex v of G.
    Initialize D[s] = 0 and D[v] = ?for each vertex v = s.
    Let a priority queue Q contain all the vertices of G using the D labels as keys.
    while Q is not empty do
        {pull a new vertex u into the cloud}
        u = value returned by Q.remove min()
       for each vertex v adjacent to u such that v is in Q do
          {perform the relaxation procedure on edge (u,v)}
          if D[u]+w(u,v) < D[v] then
              D[v] = D[u]+w(u,v)
              Change to D[v] the key of vertex v in Q.
       return the label D[v] of each vertex v