Pagini recente » Cod sursa (job #2165727) | Cod sursa (job #141450) | Cod sursa (job #936497) | Cod sursa (job #2128240) | Cod sursa (job #2420429)
#include <iostream>
#include <fstream>
using namespace std;
#define NMAX 105
#define INFINIT 10000000
ifstream fin("royfloyd.in");
ofstream fout("royfloyd.out");
int nrNoduri, matriceCosturi[NMAX][NMAX];
void royFloyd(){
for ( int k = 1; k <= nrNoduri; k++)
for ( int i = 1; i <= nrNoduri; i++)
for ( int j = 1; j <= nrNoduri; j++)
if ( matriceCosturi[i][j] > matriceCosturi[i][k] + matriceCosturi[k][j] )
matriceCosturi[i][j] = matriceCosturi[i][k] + matriceCosturi[k][j];
}
int main(){
fin >> nrNoduri;
for ( int i = 1; i <= nrNoduri; i++)
for ( int j = 1; j <= nrNoduri; j++)
fin >> matriceCosturi[i][j];
for ( int i = 1; i <= nrNoduri; i++)
for ( int j = 1; j <= nrNoduri; j++)
if ( i != j && matriceCosturi[i][j] == 0 )
matriceCosturi[i][j] = INFINIT;
royFloyd();
for ( int i = 1; i <= nrNoduri; i++){
for ( int j = 1; j <= nrNoduri; j++)
fout << matriceCosturi[i][j] << " ";
fout << "\n";
}
return 0;
}