#include #include #include using namespace std; const int INF = INT_MAX; void floydWarshall(vector>& graph,int V) { vector> dist(graph); for (int k = 0; k < V; k++) { for (int i = 0; i < V; i++) { for (int j = 0; j < V; j++) { if (dist[i][k] != INF && dist[k][j] != INF && dist[i][k] + dist[k][j] < dist[i][j]) { dist[i][j] = dist[i][k] + dist[k][j]; } } } } // Print the shortest distances between all pairs of vertices for (int i = 0; i < V; i++) { for (int j = 0; j < V; j++) { if (dist[i][j] == INF) { cout << "INF\t"; } else { cout << dist[i][j] << "\t"; } } cout << endl; } } int main() { // Initialize the adjacency matrix with edge weights vector> graph = { {0 ,3,INF, 7}, {8, 0, 2, INF}, {5, INF, 0, 1}, {2,INF,INF,0} }; floydWarshall(graph,4); return 0; }