Pagini recente » Cod sursa (job #1170394) | Cod sursa (job #891954) | Cod sursa (job #697792) | Cod sursa (job #1215185) | Cod sursa (job #2858690)
#include <bits/stdc++.h>
using namespace std;
ifstream in ("royfloyd.in");
ofstream out ("royfloyd.out");
int a[101][101];
void solve()
{
int n;
in >> n;
for (int i = 1;i<=n;++i)
for (int j = 1;j<=n;++j)
in >> a[i][j];
for (int k = 1;k<=n;++k)
for (int i = 1;i<=n;++i)
for (int j = 1;j<=n;++j)
if (a[i][k] && a[k][j] && a[i][k] + a[k][j] < a[i][j])
a[i][j] = a[i][k] + a[k][j];
for (int i = 1;i<=n;++i)
{
for (int j = 1;j<=n;++j)
out << a[i][j] << ' ';
out << '\n';
}
}
main ()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t = 1;
//cin >> t;
while (t--)
solve();
return 0;
}