/| | \|( )>( note that the value of graph[ ][jis if is equal to and graph[ ][jis inf (infiniteif there is no edge from vertex to outputshortest distance matrix inf inf inf inf inf inf floyd warshall algorithm we initialize the solution matrix same as the input graph matrix as first step then we update the solution matrix by considering all vertices as an intermediate vertex the idea is to one by one pick all vertices and update all shortest paths which include the picked vertex as an intermediate vertex in the shortest path when we pick vertex number as an intermediate vertexwe already have considered vertices { - as intermediate vertices for every pair (ijof source and destination vertices respectivelythere are two possible cases is not an intermediate vertex in shortest path from to we keep the value of dist[ ][jas it is is an intermediate vertex in shortest path from to we update the value of dist[ ][jas dist[ ][kdist[ ][jthe following figure shows the above optimal substructure property in the all-pairs shortest path problem