Pagini recente » Cod sursa (job #1223693) | Cod sursa (job #2863356) | Cod sursa (job #2419681) | Cod sursa (job #1532735) | Cod sursa (job #1470032)
#include <cstdio>
using namespace std;
const int nmx = 103;
int n, mat[nmx][nmx];
void citire(){
scanf("%d", &n);
for(int i = 1; i <= n; ++i)
for(int j = 1; j <= n; ++j)
scanf("%d", &mat[i][j]);
}
void roy_floyd(){
for(int q = 1; q <= n; ++q)
for(int i = 1; i <= n; ++i)
for(int j = 1; j <= n; ++j)
if(i != j && mat[i][q] && mat[q][j] && (not mat[i][j] || mat[i][j] > mat[i][q] + mat[q][j]))
mat[i][j] = mat[i][q] + mat[q][j];
}
void afisare(){
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();
roy_floyd();
afisare();
return 0;
}