Pagini recente » Cod sursa (job #1510073) | Cod sursa (job #1926028) | Cod sursa (job #1276006) | Cod sursa (job #3242869) | Cod sursa (job #2489533)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("royfloyd.in");
ofstream fout("royfloyd.out");
#define cin fin
#define cout fout
int n, m, x, y, cost;
int a[101][101];
void read_graph()
{
cin >> n >> m;
for(int i=1; i<=m; i++)
{
cin >> x >> y >> cost;
a[x][y] = cost;
}
}
void read_mat()
{
cin >> n;
for(int i=1; i<=n; i++)
{
for(int j=1; j<=n; j++)
{
cin >> a[i][j];
}
}
}
void solve()
{
for(int k=1; k<=n; k++)
{
for(int i=1; i<=n; i++)
{
for(int j=1; j<=n; j++)
{
if(((a[i][j] > a[i][k] + a[k][j]) || !a[i][j]) && i != j && a[i][k] && a[k][j])
{
a[i][j] = a[i][k] + a[k][j];
}
}
}
}
}
void print()
{
for(int i=1; i<=n; i++)
{
for(int j=1; j<=n; j++)
{
cout << a[i][j] << " ";
}
cout << endl;
}
}
int main()
{
read_mat();
solve();
print();
}