Pagini recente » Istoria paginii runda/sim0004/clasament | Cod sursa (job #1244866) | Cod sursa (job #2339856) | Cod sursa (job #683089) | Cod sursa (job #1974614)
#include <iostream>
#include <fstream>
using namespace std;
const int nMax = 105;
const int INF = (1 << 26);
int n;
int cost[nMax][nMax];
int dp[nMax][nMax][nMax];
void citire()
{
ifstream in("royfloyd.in");
in >> n;
for(int i = 1; i <= n; ++i)
for(int j = 1; j <= n; ++j)
{
in >> cost[i][j];
if(i != j && cost[i][j] == 0)
cost[i][j] = INF;
}
in.close();
}
void rezolvare()
{
for(int i = 1; i <= n; ++i)
for(int j = 1; j <= n; ++j)
dp[0][i][j] = cost[i][j];
for(int k = 1; k <= n; ++k)
for(int i = 1; i <= n; ++i)
for(int j = 1; j <= n; ++j)
{
dp[k][i][j] = min(dp[k-1][i][j], dp[k-1][i][k] + dp[k-1][k][j]);
}
ofstream out("royfloyd.out");
for(int i = 1; i <= n; ++i)
{
for(int j = 1; j <= n; ++j)
{
out << dp[n][i][j] << " ";
}
out << "\n";
}
out.close();
}
int main()
{
citire();
rezolvare();
return 0;
}