Pagini recente » Cod sursa (job #1626981) | Cod sursa (job #2023317) | Cod sursa (job #316968) | Cod sursa (job #422511) | Cod sursa (job #2677239)
#include <iostream>
#include <fstream>
using namespace std;
const int NMAX = 100;
int cost[NMAX + 1][NMAX + 1];
int main() {
ifstream fin( "royfloyd.in" );
ofstream fout( "royfloyd.out" );
int i, j, k, n;
fin >> n;
for ( i = 1; i <= n; i ++ ) {
for ( j = 1; j <= n; j ++ )
fin >> cost[i][j];
}
for ( k = 1; k <= n; k ++ ) {
for ( i = 1; i <= n; i ++ ) {
for ( j = 1; j <= n; j ++ ) {
if ( cost[i][j] && cost[k][j] && ( cost[i][k] + cost[k][j] < cost[i][j] || cost[i][j] == 0 ) && i != j )
cost[i][j] = cost[i][k] + cost[k][j];
}
}
}
for ( i = 1; i <= n; i ++ ) {
for ( j = 1; j <= n; j ++ )
fout << cost[i][j] << ' ';
fout << '\n';
}
return 0;
}