Pagini recente » Cod sursa (job #1182085) | Cod sursa (job #362491) | Cod sursa (job #702570) | Cod sursa (job #2279341) | Cod sursa (job #2740564)
#include <bits/stdc++.h>
using namespace std;
#ifndef LOCAL
ifstream in("royfloyd.in");
ofstream out("royfloyd.out");
#define cin in
#define cout out
#endif //LOCAL
const int NMAX = 128;
int mat[NMAX][NMAX];
int main()
{
int n; cin >> n;
for(int i = 0; i < n; i++)
for(int j = 0; j < n; j++)
{
cin >> mat[i][j];
if(mat[i][j] == 0)
mat[i][j] = 1e6;
if(i == j)
mat[i][j] = 0;
}
for(int k = 0; k < n; k++)
for(int i = 0; i < n; i++)
for(int j = 0; j < n; j++)
mat[i][j] = min(mat[i][j], mat[i][k] + mat[k][j]);
for(int i = 0; i < n; i++)
{
for(int j = 0; j < n; j++)
cout << mat[i][j] << ' ';
cout << '\n';
}
}