Pagini recente » Cod sursa (job #2768538) | Cod sursa (job #725039) | Cod sursa (job #2224027) | Monitorul de evaluare | Cod sursa (job #2561031)
#include <iostream>
#include <fstream>
using namespace std;
ifstream in("royfloyd.in");
ofstream out("royfloyd.out");
const int maxn = 105;
int cost[maxn][maxn];
int main()
{
int n;
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)
cost[i][j] = (1 << 25);
}
}
for(int k = 1; k <= n; k++)
for(int i = 1; i <= n; i++)
for(int j = 1; j <= n; j++)
if(i != k && i != j && k != j && cost[i][j] > cost[i][k] + cost[k][j])
cost[i][j] = cost[i][k] + cost[k][j];
for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= n; j++)
{
if(cost[i][j] == (1 << 25))
out << 0 << " ";
else
out << cost[i][j] << " ";
}
out << "\n";
}
return 0;
}