Cod sursa(job #2004268)

Utilizator LucaSeriSeritan Luca LucaSeri Data 25 iulie 2017 13:53:48
Problema Floyd-Warshall/Roy-Floyd Scor 50
Compilator cpp Status done
Runda Arhiva educationala Marime 0.73 kb
#include <fstream>

using namespace std;

const int MaxN = 101;

ifstream f("royfloyd.in");
ofstream g("royfloyd.out");

int mat[MaxN][MaxN];

int main()
{
    int n;
    f >> n;
    for(int i = 0; i < n; ++i){
        for(int j = 0; j < n; ++j){
            f >> mat[i][j];
        }
    }

    for(int k = 0; k < n; ++k){
        for(int i = 0; i < n; ++i){
            for(int j = 0; j < n; ++j){
                if(mat[i][k] + mat[k][j] < mat[i][j]){
                    mat[i][j] = mat[i][k] + mat[k][j];
                }
            }
        }
    }

    for(int i = 0; i < n; ++i){
        for(int j = 0; j < n; ++j){
            g << mat[i][j] << ' ';
        }
        g << '\n';
    }
    return 0;
}