Pagini recente » Cod sursa (job #819398) | Cod sursa (job #508779) | Cod sursa (job #2390055) | Cod sursa (job #487187) | Cod sursa (job #1443829)
#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 k = 1; k <= n; ++k)
for(int i = 1; i <= n; ++i)
for(int j = 1; j <= n; ++j)
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;
}