#include #include using namespace std; void floydWarshall(vector>& graph) { int V = graph.size(); int INT_MAX; vector> dist(V, vector(V, INT_MAX)); for (int i = 0; i < V; i++) { for (int j = 0; j < V; j++) { if (i == j) { dist[i][j] = 0; } else if (graph[i][j] != 0) { dist[i][j] = graph[i][j]; } } } 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] != INT_MAX && dist[k][j] != INT_MAX) { dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]); } } } } for (int i = 0; i < V; i++) { for (int j = 0; j < V; j++) { cout << "Shortest path from " << i << " to " << j << ": " << dist[i][j] << endl; } } } int main() { vector> graph = { {0, 3, 0, 0, 0, 0}, {0, 0, 8, 0, 0, 2}, {0, 0, 0, 0, 0, 0}, {0, 5, 10, 0, 0, 0}, {0, 0, 2, 1, 0, 0}, {0, 0, 0, 7, 4, 0} }; floydWarshall(graph); return 0; }