Pagini recente » Cod sursa (job #113760) | Cod sursa (job #188054) | Cod sursa (job #1574017) | Cod sursa (job #972983) | Cod sursa (job #1528441)
#include <iostream>
#include <fstream>
using namespace std;
const int INF = 2000000000;
const int Nmax = 105;
int N, A[Nmax][Nmax];
void read()
{
ifstream f("royfloyd.in");
f >> N;
for(int i = 1; i <= N; i ++)
{
for(int j = 1; j <= N; j ++)
{
f >> A[i][j];
}
}
f.close();
}
void RoyFloyd()
{
//I initialize the minimal cost matrix when I read the original one
for(int k = 1; k <= N; k ++)
{
for(int i = 1; i <= N; i ++)
{
for(int j = 1; j <= N; j ++)
{
if(A[i][k] && A[k][j] && ((A[i][j] > A[i][k]+A[k][j]) || !A[i][j]) && (i != j))
{
A[i][j] = A[i][k] + A[k][j];
}
}
}
}
}
void print()
{
ofstream g("royfloyd.out");
for(int i = 1; i <= N; i ++)
{
for(int j = 1; j <= N; j ++)
{
g << A[i][j] << " ";
}
g << "\n";
}
}
int main()
{
read();
RoyFloyd();
print();
return 0;
}