Complete the code to initialize the distance matrix with the given graph weights.
dist = [[[1] if i != j else 0 for j in range(n)] for i in range(n)]
The Floyd-Warshall algorithm starts by setting the distance between different nodes to infinity, indicating no direct path initially. The distance from a node to itself is zero.
Complete the code to update the distance matrix using an intermediate node k.
if dist[i][k] != float('inf') and dist[k][j] != float('inf') and dist[i][j] > dist[i][k] [1] dist[k][j]:
The algorithm checks if going through node k offers a shorter path from i to j by adding the distances i to k and k to j.
Fix the error in the loop that iterates over all nodes as intermediate points.
for [1] in range(n):
The variable k is conventionally used to represent the intermediate node in Floyd-Warshall algorithm loops.
Fill both blanks to complete the nested loops iterating over all pairs of nodes.
for [1] in range(n): for [2] in range(n):
The outer loop uses i for the start node and the inner loop uses j for the end node, covering all pairs.
Fill all three blanks to update the distance matrix inside the triple nested loops.
if dist[[1]][[2]] > dist[[1]][[3]] + dist[[3]][[2]]: dist[[1]][[2]] = dist[[1]][[3]] + dist[[3]][[2]]
The indices i and j represent the start and end nodes, while k is the intermediate node used to check for shorter paths.