
For each edge (u,v)∈E:ℓ(u,v)←w(v),ℓ(v,u)←w(u).Initialize:pq←Create-Priority-Queue(),π(v)←∞ for all v=s,π(s)←0,insert each v∈V into pq with key π(v).While pq is not empty:u←DEL-MIN(pq).For each edge (u,v)∈E leaving u:if π(v)>π(u)+ℓ(u,v) thenDECREASE-KEY(pq,v,π(u)+ℓ(u,v)),π(v)←π(u)+ℓ(u,v),pred(v)←u.Reconstruct shortest path:shortestPath←∅,curr←t;while curr=s:prepend curr to shortestPath,curr←pred(curr);prepend s to shortestPath. 
Create a new graph G′=(V′,E′) with (city, time) pairs as verticesBuild vertices:FOREACH vertex c∈V:FOR t=0 to T:Add pair (c,t) to V′Add flight edges:FOREACH edge (u,v)∈E:FOREACH flight (departure_time,cost)∈timetable[u][v]:arrival_time=departure_time+d(u,v)IF arrival_time≤T:Add ((u,departure_time),(v,arrival_time),cost) to E′Add waiting edges:FOREACH vertex c∈V:FOR t=0 to T−1:Add ((c,t),(c,t+1),0) to E′Run Dijkstra on G′:distances, predecessors=Dijkstra(G′,(s,0))Find minimum cost and destination node:min_cost=∞final_destination_node=nullFOR t=0 to T:IF distances[(v,t)]<min_cost:min_cost=distances[(v,t)]final_destination_node=(v,t)Backtrack to get the cheapest route :route=new Listcurrent_node=final_destination_nodeWHILE current_node=null:Add current_node to the front of the route listcurrent_node=predecessors[current_node]Return route 
a.)
Initialization:For all states (i,j,dir):dist[i,j,dir]←∞,pred[i,j,dir]←null.Set dist[1,1,North]←0.PQ←Create-Min-PQ(),insert every state (i,j,dir) into PQ with key dist[⋅].Main loop:while PQ is not empty:u←EXTRACT-MIN(PQ)(where u=(i,j,dir)).For each valid neighbor state v of u (forward, left, right):if dist[u]+1<dist[v] thendist[v]←dist[u]+1,pred[v]←u,DECREASE-KEY(PQ,v,dist[v]).Find the solution:d∗=min{dist[n,n,North],dist[n,n,East],dist[n,n,South],dist[n,n,West]}.If d∗=∞ then the goal is unreachable. Otherwise, reconstruct the shortest path by backtracking from thestate among {(n,n,∗)} with value d∗ using the pred pointers. b.)
Initialization:Q←Create-Queue(),enqueue(Q,start_state),dist[start_state]←0,pred[start_state]←null.Main loop (BFS over joint states):while Q is not empty:Ucurr←dequeue(Q).if Ucurr is the goal state thenreconstruct and return path by backtracking using pred (length dist[Ucurr]).Generate all combined moves M (size 3k) for the k robots.for each m∈M:Unext←apply(m,Ucurr).Check validity: Unext is valid if(i) every robot position is in-bounds,(ii) no robot is on a static obstacle,(iii) no two robots occupy the same cell,(iv) no two robots swap positions in this step.If Unext is valid and not visited:dist[Unext]←dist[Ucurr]+1,pred[Unext]←Ucurr,enqueue(Q,Unext).Termination:If the loop ends without reaching the goal, return “No path exists.” 
a & b
Initialize:Make a disjoint-set (Union-Find) UF with a separate set for each v∈V,T←∅.Process critical edges F:for each (u,v)∈F:if findUF(u)=findUF(v)error: critical edges in F form a cycle,elseT←T∪{(u,v)},unionUF(u,v).Process remaining edges:R←E∖F,sort R by non-decreasing weight,for each (u,v)∈R:if findUF(u)=findUF(v) thenT←T∪{(u,v)},unionUF(u,v).Return: T. c.)
Processing Critical Edges
- There are |F| critical edges
- loop through each edges and perform union-find
- union-find is nearly constant time on average
- Since F is a subset of E it will take at most O(|E|) time
Sorting the Remaining Edges:
- Sorting the edges that are not in F. |E| - |F| which is in the order of O(|E|)
- To sort the remaining edges it will take O(|E|log|E|) time
Looping through Remaining Edges:
- This will take approximately O(|E|) time.
Combining these gives the total time of O(|E|) + O(|E|log|E|) + O(|E|).
The dominant term is O(|E|log|E|) which give the overall running time of the algorithm.