Pagini recente » Cod sursa (job #1293228) | Cod sursa (job #2489054) | Cod sursa (job #741068) | Cod sursa (job #1704496) | Cod sursa (job #524595)
Cod sursa(job #524595)
#include <iostream>
#include <fstream>
using namespace std;
const char iname[] = "royfloyd.in";
const char oname[] = "royfloyd.out";
ifstream fin(iname);
ofstream fout(oname);
int A[128][128], i, j, n, k, cost[128][128];
int main()
{
fin >> n;
for(i = 1; i <= n; i ++)
for(j = 1; j <= n; j ++)
{
fin >> A[i][j];
cost[i][j] = A[i][j];
if(A[i][j] == 0)
cost[i][j] = 23232323;
}
for(k = 1; k <= n; k ++)
for(i = 1; i <= n; i ++)
for(j = 1; j <= n; j ++)
cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);
for(i = 1; i <= n; i ++)
{
for(j = 1; j <= n; j ++)
{
if(cost[i][j] == 23232323)
fout << "0 ";
else
fout << cost[i][j] << " ";
}
fout << "\n";
}
return 0;
}