Pagini recente » Cod sursa (job #2693235) | Cod sursa (job #202158) | Cod sursa (job #2810769) | Cod sursa (job #2284967) | Cod sursa (job #2409997)
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 101;
int mat[MAXN][MAXN];
int main() {
#ifdef BLAT
freopen("input", "r", stdin);
#else
freopen("royfloyd.in", "r", stdin);
freopen("royfloyd.out", "w", stdout);
#endif
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
for(int i = 0; i < n; ++i) {
for(int j = 0; j < n; ++j) cin >> mat[i][j];
}
for(int k = 0; k < n; ++k)
for(int i = 0; i < n; ++i)
for(int j = 0; j < n; ++j)
if(mat[i][k] && mat[k][j] && (mat[i][k] + mat[k][j] < mat[i][j] || mat[i][j] == 0)) mat[i][j] = mat[i][k] + mat[k][j];
for(int i = 0; i < n; ++i) {
mat[i][i] = 0;
for(int j = 0; j < n; ++j) cout << mat[i][j] << ' ';
cout << '\n';
}
return 0;
}