Complete the code to initialize the distance matrix with the given graph weights.
for (int i = 0; i < V; i++) { for (int j = 0; j < V; j++) { dist[i][j] = graph[i][j]; if (i == j) { dist[i][j] = [1]; } } }
Distance from a vertex to itself is always 0.
Complete the code to update the distance if a shorter path is found through vertex k.
if (dist[i][k] != INF && dist[k][j] != INF && dist[i][k] + dist[k][j] < [1]) { dist[i][j] = dist[i][k] + dist[k][j]; }
We update dist[i][j] only if the new path through k is shorter than the current dist[i][j].
Fix the error in the nested loops to correctly iterate over all vertices.
for (int k = 0; k < V; k++) { for (int i = 0; i < V; i++) { for (int j = 0; j < [1]; j++) { // update dist[i][j] } } }
All loops must run from 0 to V-1 to cover all vertices.
Fill both blanks to correctly print the final distance matrix after Floyd Warshall algorithm.
for (int i = 0; i < V; i++) { for (int j = 0; j < V; j++) { if (dist[i][j] == [1]) printf("%s ", "INF"); else printf("%d ", [2]); } printf("\n"); }
If distance is INF, print "INF"; otherwise print the distance value dist[i][j].
Fill all three blanks to complete the Floyd Warshall update step inside the triple nested loops.
if (dist[i][[1]] != INF && dist[[2]][j] != INF && dist[i][[3]] + dist[[2]][j] < dist[i][j]) { dist[i][j] = dist[i][[3]] + dist[[2]][j]; }
All blanks refer to the intermediate vertex k used to check and update the shortest path.