Cod sursa(job #2302764)

Utilizator SweetHumanAvram Gheorghe SweetHuman Data 15 decembrie 2018 10:01:30
Problema Floyd-Warshall/Roy-Floyd Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.81 kb
#include <iostream>
#include <fstream>
#define MAXIMO 999999
using namespace std;
int matrixDeIntermed[102][102],n;
ifstream f1("royfloyd.in");
ofstream f2("royfloyd.out");
int main() {
    f1>>n;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            f1>>matrixDeIntermed[i][j];
            if(matrixDeIntermed[i][j]==0 && i != j) matrixDeIntermed[i][j]=MAXIMO/2;
        }
    }

    for(int k=1;k<=n;k++) {
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= n; j++) {
               if(i != j) matrixDeIntermed[i][j]=min(matrixDeIntermed[i][j],matrixDeIntermed[i][k]+matrixDeIntermed[k][j]);
            }
        }
    }

    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            f2<<matrixDeIntermed[i][j]<<" ";
        }
        f2<<'\n';
    }


    return 0;
}