Cod sursa(job #3205133)

Utilizator AndreasBossGamerBaragau Andreas AndreasBossGamer Data 18 februarie 2024 21:31:49
Problema Floyd-Warshall/Roy-Floyd Scor 50
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.64 kb
#include <fstream>
#include <vector>

using namespace std;

ifstream cin("royfloyd.in");
ofstream cout("royfloyd.out");

int n, m;

int adj[101][101];

int main()
{
    cin >> n;
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
            cin >> adj[i][j];
    for (int k = 0; k < n; k++)
        for (int i = 0; i < n; i++)
            for (int j = 0; j < n; j++)
                if ((adj[i][k] + adj[k][j] < adj[i][j]) && i != j) adj[i][j] = adj[i][k] + adj[k][j];
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++) cout << adj[i][j] << " ";
        cout << '\n';
    }
        
}