Pagini recente » Cod sursa (job #204479) | Cod sursa (job #1571446) | Istoria paginii utilizator/zuzuleinen | Monitorul de evaluare | Cod sursa (job #3130853)
#include <fstream>
using namespace std;
ifstream in("royfloyd.in");
ofstream out("royfloyd.out");
const int N = 101;
const int INF = 100000;
int cost[N][N], n;
int main()
{
in >> n;
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= n; j++)
{
in >> cost[i][j];
if (cost[i][j] == 0 && i != j)
{
cost[i][j] = INF;
}
}
}
for (int k = 1; k <= n; k++)
{
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= n; j++)
{
cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);
}
}
}
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= n; j++)
{
if (i != j && cost[i][j] == INF)
{
out << "0 ";
}
else
{
out << cost[i][j] << " ";
}
}
out << "\n";
}
return 0;
}