Cod sursa(job #2951138)

Utilizator sdragosSandu Dragos sdragos Data 5 decembrie 2022 15:40:34
Problema Floyd-Warshall/Roy-Floyd Scor 20
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.83 kb
#include <fstream>
#include <cstring>
#include <vector>
#include <algorithm>
//#include <iostream>
#include <queue>
using namespace std;

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

int n, mat[105][105];

int main(void)
{
    cin >> n;
    for(int i = 1; i <= n; i++)
        for(int j = 1; j <= n; j++)
            cin >> mat[i][j];

    for(int i = 1; i <= n; i++)
        for(int j = 1; j <= n; j++)
            for(int k = 1; k <= n; k++)
                if(i != k && j != k)
                    if(mat[i][k] && mat[k][j] && (mat[i][k] + mat[k][j] < mat[i][j] || mat[i][j] == 0) && i != j)
                        mat[i][j] = mat[i][k] + mat[k][j];

    for(int i = 1; i <= n; i++)
    {
        for(int j = 1; j <= n; j++)
            cout << mat[i][j] << ' ';
        cout << '\n';
    }
}