Complete the code to initialize the distance vector with infinity.
vector<int> dist(V, [1]);We initialize distances to all vertices as infinity (INT_MAX) to represent unknown distances.
Complete the code to pick the vertex with the minimum distance not yet processed.
int u = minDistance(dist, [1]);The function minDistance needs the visited array to ignore already processed vertices.
Fix the error in the relaxation step condition to update distances correctly.
if (!visited[v] && graph[u][v] && dist[u] != INT_MAX && dist[v] [1] (dist[u] + graph[u][v])) { dist[v] = dist[u] + graph[u][v]; }
We update dist[v] only if the new path is shorter, so dist[u] + weight < dist[v]. The condition uses > to check if current dist[v] is greater than new distance.
Fill both blanks to correctly initialize and update the priority queue for Dijkstra's algorithm.
priority_queue<pair<int, int>, vector<pair<int, int>>, [1]> pq; pq.push([2], source});
Dijkstra's algorithm uses a min-heap priority queue, so we use greater<pair<int,int>> to get the smallest distance first. The initial distance pushed is 0 for the source.
Fill all three blanks to correctly update distances and push neighbors into the priority queue.
if (dist[u] + graph[u][v] [1] dist[v]) { dist[v] = dist[u] + graph[u][v]; pq.[2]([3], v); }
We update dist[v] if the new path is shorter (dist[u] + weight < dist[v]). Then we push the updated distance and vertex into the priority queue.
