Pagini recente » Cod sursa (job #715692) | Cod sursa (job #2645956) | Cod sursa (job #3260034) | Cod sursa (job #651358) | Cod sursa (job #1494656)
#include <cstdio>
#define nmx 102
#define inf 0x3f3f3f3f
using namespace std;
int n, mat[nmx][nmx];
int main(){
freopen("royfloyd.in", "r", stdin);
freopen("royfloyd.out", "w", stdout);
scanf("%d", &n);
for(int i = 1;i <= n; ++i)
for(int j = 1; j <= n; ++j){
scanf("%d", &mat[i][j]);
if(not mat[i][j])
mat[i][j] = inf;
}
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];
for(int i = 1; i <= n; ++i){
for(int j = 1; j <= n; ++j)
printf("%d ", mat[i][j] == inf ? 0 : mat[i][j]);
printf("\n");
}
return 0;
}