Cod sursa(job #2641645)

Utilizator LeCapataIustinian Serban LeCapata Data 12 august 2020 11:18:59
Problema Floyd-Warshall/Roy-Floyd Scor 90
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.75 kb
#include <fstream>
#define N 105
using namespace std;

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

int nrNod;
int cost[105][105];

int main()
{
    in>>nrNod;
    for(int i=1; i<=nrNod; ++i)
        for(int j=1; j<=nrNod; ++j){
            in>>cost[i][j];
        }

    for(int k=1; k<=nrNod; ++k)
        for(int i=1; i<=nrNod; ++i)
            for(int j=1; j<=nrNod; ++j)
                if(i!=j)
                if(cost[i][k] + cost[k][j] < cost[i][j] || cost[i][j] == 0)
                    cost[i][j] = cost[i][k] + cost[k][j];

    for(int i=1; i<=nrNod; ++i){
        for(int j=1; j<=nrNod; ++j)
            out<<cost[i][j]<<" ";
        out<<'\n';
    }

    in.close();
    out.close();
    return 0;
}