Pagini recente » Cod sursa (job #2690963) | Cod sursa (job #1628686) | Cod sursa (job #1229537) | Cod sursa (job #2569430) | Cod sursa (job #2726145)
#include <fstream>
using namespace std;
ifstream cin("royfloyd.in");
ofstream cout("royfloyd.out");
const int N = 101, INF = 1000001;
int cost[N][N], n;
void royfloyd()
{
for (int k = 1; k <= n; k++)
{
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= n; j++)
{
if (cost[i][j] > cost[i][k] + cost[k][j])
{
cost[i][j] = cost[i][k] + cost[k][j];
}
}
}
}
}
int main()
{
int i, j;
cin >> n;
for (i = 1; i <= n; i++)
{
for (j = 1; j <= n; j++)
{
cin >> cost[i][j];
if (i != j && cost[i][j] == 0)
{
cost[i][j] = INF;
}
}
}
royfloyd();
for (i = 1; i <= n; i++)
{
for (j = 1; j <= n; j++)
{
if (cost[i][j] == INF)
cout << 0 << ' ';
else
cout << cost[i][j] << ' ';
}
cout << "\n";
}
return 0;
}