Mai intai trebuie sa te autentifici.

Cod sursa(job #2340435)

Utilizator Cristi01052Tudorache Christian Cristi01052 Data 10 februarie 2019 14:09:41
Problema Floyd-Warshall/Roy-Floyd Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.76 kb
#include <fstream>

using namespace std;

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

int n, mat[105][105];

int main()
{
    cin >> n;
    for(int i = 1; i <= n; ++i)
        for(int j = 1; j <= n; ++j)
            cin >> mat[i][j];
    for(int k = 1; k <= n; ++k)
        for(int i = 1; i <= n; ++i)
            for(int j = 1; j <= n; ++j)
                if(i != j and mat[i][k] != 0 and mat[k][j] != 0)
                {
                    if(mat[i][j] == 0) mat[i][j] = 1001;
                    mat[i][j] = min(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';
    }
    return 0;
}