Pagini recente » Cod sursa (job #1837175) | Cod sursa (job #1294845) | Cod sursa (job #193758) | Profil PetrescuRobert | Cod sursa (job #3130844)
#include <fstream>
using namespace std;
const int N = 101, INF = 1001;
int cost[N+1][N+1];
int n;
ifstream in("royfloyd.in");
ofstream out("royfloyd.out");
void rf(){
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(cost[i][j] == INF)
{
cost[i][j] = 0;
}
out << cost[i][j] << ' ';
}
out << '\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;
}
}
}
rf();
return 0;
}