Pagini recente » Cod sursa (job #1885484) | Cod sursa (job #3168009) | Cod sursa (job #1732634) | Cod sursa (job #663906) | Cod sursa (job #1103948)
#include <iostream>
#include <fstream>
using namespace std;
ifstream f ("royfloyd.in");
ofstream g ("royfloyd.out");
const int inf = 999999;
int n, cost[101][101];
void citeste ()
{
f >> n;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
{
f >> cost[i][j];
if (i != j && cost[i][j] == 0) cost[i][j]=inf;
}
}
void royfloyd ()
{
int k, i, j;
for (k = 1; k <= n; k++)
for (i = 1; i <= n; i++)
for (j = 1; j <=n ; j++)
cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);
}
void scrieMatrice ()
{
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= n; j++)
if (cost[i][j] == inf) g << 0 << ' ';
else g << cost[i][j]<<' ';
g<<'\n';
}
}
int main()
{
citeste ();
royfloyd ();
scrieMatrice ();
return 0;
}