#include <stdio.h>
#include <limits.h>
#define INF INT_MAX
#define V 4 // Number of vertices in the graph
// Function to print the distance matrix
void printSolution(int dist[V][V]);
// Implementation of the Floyd-Warshall algorithm
void floyd_warshall(int graph[V][V]) {
 int dist[V][V];
 int i, j, k;
 // Initialize the distance matrix with the given graph weights
 for (i = 0; i < V; i++) {
 for (j = 0; j < V; j++) {
 dist[i][j] = graph[i][j];
 }
 }
 // Compute shortest paths
 for (k = 0; k < V; k++) {
 for (i = 0; i < V; i++) {
 for (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 distance matrix
 printSolution(dist);
}
// Function to print the distance matrix
void printSolution(int dist[V][V]) {
 printf("The shortest distances between every pair of vertices are:\n");
 for (int i = 0; i < V; i++) {
 for (int j = 0; j < V; j++) {
 if (dist[i][j] == INF)
 printf("%7s", "INF");
 else
 printf("%7d", dist[i][j]);
 }
 printf("\n");
 }
}
int main() {
 // Example graph represented as an adjacency matrix
 int graph[V][V] = { {0, 5, INF, 10},
 {INF, 0, 3, INF},
 {INF, INF, 0, 1},
 {INF, INF, INF, 0} };
 // Run the Floyd-Warshall algorithm
 floyd_warshall(graph);
 return 0;
}