Pagini recente » Cod sursa (job #2625703) | Cod sursa (job #2579917) | Cod sursa (job #222894) | Cod sursa (job #2105393) | Cod sursa (job #2677227)
#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] > 0 && cost[k][j] > 0 && ( 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;
}