#include <iostream>
#include <climits>
#include <vector>
using namespace std;

#define INF 99999
void floydWarshall(int dist[][10], int V) {

    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][j] > dist[i][k] + dist[k][j]) {
                    dist[i][j] = dist[i][k] + dist[k][j];
                }
            }
        }
    }


    cout << "The shortest distance matrix is: \n";
    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() {
    int V, E;


    cout << "Enter the number of vertices: ";
    cin >> V;
    cout << "Enter the number of edges: ";
    cin >> E;


    int dist[10][10];
    for (int i = 0; i < V; i++) {
        for (int j = 0; j < V; j++) {
            if (i == j) {
                dist[i][j] = 0;
            } else {
                dist[i][j] = INF;
            }
        }
    }


    cout << "Enter the edges (source vertex, destination vertex, and weight):\n";
    for (int i = 0; i < E; i++) {
        int u, v, weight;
        cout << "Edge " << i + 1 << " (source destination weight): ";
        cin >> u >> v >> weight;


        dist[u][v] = weight;
    }


    floydWarshall(dist, V);

    return 0;
}
