Pagini recente » Cod sursa (job #1524857) | Cod sursa (job #390747) | Cod sursa (job #1485678) | Cod sursa (job #2929766) | Cod sursa (job #2858691)
#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]) && 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;
}