Pagini recente » Cod sursa (job #1447614) | Cod sursa (job #932989) | Cod sursa (job #1938604) | Cod sursa (job #2028113) | Cod sursa (job #2422312)
#include <iostream>
#include <fstream>
#include <vector>
#define MAX_NODS 105
#define MAX_VAL 20000
int cost[MAX_NODS][MAX_NODS];
using namespace std;
int main()
{
ifstream f("royfloyd.in");
ofstream g("royfloyd.out");
int N;
f>>N;
for(int i = 1; i <= N; i++)
{
for(int j = 1; j <= N; j++)
{
f>>cost[i][j];
if(i != j && cost[i][j] == 0) cost[i][j] = MAX_VAL;
}
}
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];
}
}
}
}
for(int i = 1; i <= N; i++)
{
for(int j = 1; j <= N; j++)
{
if(cost[i][j] == MAX_VAL) g<<"0 ";
else
g<<cost[i][j]<<" ";
}
g<<"\n";
}
return 0;
}