graph algorithms def shortest path lengths(gsrc) """compute shortest-path distances from src to reachable vertices of graph can be undirected or directedbut must be weighted such that element(returns numeric weight for each edge return dictionary mapping each reachable vertex to its distance from src "" ={ [vis upper bound from to cloud map reachable to its [vvalue pq adaptableheappriorityqueuevertex will have key [ pqlocator map from vertex to its pq locator for each vertex of the graphadd an entry to the priority queuewith the source having distance and all others having infinite distance for in vertices) if is src [ elsesyntax for positive infinity [vfloatinf pqlocator[vpq add( [ ]vsave locator for future updates while not pq is empty) keyu pq remove min cloud[ukey its correct [uvalue del pqlocator[uu is no longer in pq outgoing edges ( , for in incident edges( ) opposite( if not in cloud perform relaxation step on edge ( , wgt element if [uwgt [ ]better path to [vd[uwgt update the distance pq update(pqlocator[ ] [ ]vupdate the pq entry return cloud only includes reachable vertices code fragment python implementation of dijkstra' algorithm for computing the shortest-path distances from single source we assume that elementfor edge represents the weight of that edge