Cod sursa(job #2815021)

Utilizator FraNNNkieFrancesco-Gregorio Petrovici FraNNNkie Data 8 decembrie 2021 23:21:41
Problema Floyd-Warshall/Roy-Floyd Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.83 kb
#include <climits>
#include <fstream>
#include <cmath>
using namespace std;

long long mat[101][101];
int n;

int main(){
    ifstream f("royfloyd.in");
    ofstream g("royfloyd.out");
    f >> n;
    for(int i = 1; i <= n; ++i){
        for(int j = 1; j <= n; ++j){
            f >> mat[i][j];
            if(i != j && mat[i][j] == 0){
                mat[i][j] = INT_MAX;
            }
        }
    }

    for(int k = 1; k <= n; ++k){
        for(int i = 1; i <= n; ++i){
                for(int j = 1; j <= n; ++j){
                        if(i != j)
                            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){
            g << mat[i][j] << " ";
        }
        g << "\n";
    }
}