Pagini recente » Cod sursa (job #469984) | Cod sursa (job #3252693) | Cod sursa (job #2328549) | Cod sursa (job #901432) | Cod sursa (job #1607570)
#include <cstdio>
using namespace std;
const int nmx = 102;
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]);
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][j] && 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]);
printf("\n");
}
return 0;
}