Pagini recente » Cod sursa (job #317834) | Cod sursa (job #1648774) | Cod sursa (job #3122570) | Cod sursa (job #1240182) | Cod sursa (job #1443828)
#include <iostream>
#include <cstdio>
using namespace std;
const int nmx = 105;
int n, mat[nmx][nmx];
inline void citire(){
scanf("%d", &n);
for(int i = 1; i <= n; ++i)
for(int j = 1; j <= n; ++j)
scanf("%d", &mat[i][j]);
}
inline void calcul(){
for(int i = 1; i <= n; ++i)
for(int j = 1; j <= n; ++j)
for(int k = 1; k <= n; ++k)
if(i != j &&mat[i][k] && mat[k][j] && (not mat[i][j] || mat[i][j] > mat[i][k] + mat[k][j] ))
mat[i][j] = mat[i][k] + mat[k][j];
}
inline void afish(){
for(int i = 1; i <= n; ++i){
for(int j = 1; j <= n; ++j)
printf("%d ", mat[i][j]);
printf("\n");
}
}
int main(){
freopen("royfloyd.in", "r", stdin);
freopen("royfloyd.out", "w", stdout);
citire();
calcul();
afish();
return 0;
}