Pagini recente » Cod sursa (job #2020466) | Cod sursa (job #3129971) | Cod sursa (job #1675280) | Cod sursa (job #1226170) | Cod sursa (job #2943083)
#include <fstream>
#define MAXN 100
#define INF 100001
using namespace std;
ifstream fin( "royfloyd.in" );
ofstream fout( "royfloyd.out" );
int cost[MAXN + 1][MAXN + 1];
int main(){
int n, i, j, k;
fin >> n;
for( i = 1; i <= n; i++ ){
for( j = 1; j <= n; j++ ){
fin >> cost[i][j];
if( cost[i][j] == 0 )
cost[i][j] = INF;
}
}
for( k = 1; k <= n; k++ )
for( i = 1; i <= n; i++ )
for( j = 1; j <= n; j++ )
if( i != j )
cost[i][j] = min( cost[i][j], cost[i][k] + cost[k][j] );
for( i = 1; i <= n; i++ ){
for( j = 1; j <= n; j++ ){
if( cost[i][j] == INF )
fout << "0 ";
else
fout << cost[i][j] << ' ';
}
fout << '\n';
}
return 0;
}