Pagini recente » Cod sursa (job #31687) | Cod sursa (job #684261) | Cod sursa (job #2887986) | Cod sursa (job #2591696) | Cod sursa (job #525768)
Cod sursa(job #525768)
#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)
A[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;
}