Pagini recente » Cod sursa (job #47100) | Cod sursa (job #1452372) | Cod sursa (job #137693) | Cod sursa (job #2223761) | Cod sursa (job #3130827)
#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] = {INF}, pred[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];
}
}
for (int k = 1; k <= n; k++)
{
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= n; j++)
{
if (cost[i][k] + cost[k][j] < cost[i][j])
{
cost[i][j] = cost[i][k] + cost[k][j];
pred[i][j] = pred[k][j];
}
}
}
}
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= n; j++)
{
out << cost[i][j] << " ";
}
out << "\n";
}
return 0;
}