Pagini recente » Cod sursa (job #225018) | Cod sursa (job #2346120) | Cod sursa (job #2961300) | Cod sursa (job #3285185) | Cod sursa (job #3215902)
#include <bits/stdc++.h>
using namespace std;
ifstream in("royfloyd.in");
ofstream out("royfloyd.out");
#define pii pair<int, int>
#define pb push_back
#define fi first
#define se second
const int NMAX = 1e5 + 30;
const int INF = 0x3f3f3f3f;
int n, m[105][105], rfw[105][105];
void read()
{
in >> n;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
{
in >> m[i][j];
if (i != j && !m[i][j])
m[i][j] = INF;
rfw[i][j] = m[i][j];
}
}
void RFW()
{
for (int k = 1; k <= n; k++)
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
if (i!=j) rfw[i][j] = min(rfw[i][j], rfw[i][k] + rfw[k][j]);
}
void solve()
{
RFW();
for (int i = 1; i <= n; i++, out << '\n')
for (int j = 1; j <= n; j++)
rfw[i][j] == INF ? out<<0<<' ' : out<<rfw[i][j]<<' ';
}
int main()
{
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(false);
read();
solve();
return 0;
}