Pagini recente » Cod sursa (job #481589) | Istoria paginii runda/ce_concurs | Istoria paginii runda/000000/clasament | Cod sursa (job #2948946) | Cod sursa (job #527436)
Cod sursa(job #527436)
#include <iostream>
#include <fstream>
using namespace std;
const char iname[] = "royfloyd.in";
const char oname[] = "royfloyd.out";
const int nmax = 128;
const int inf = 29219009;
ifstream fin(iname);
ofstream fout(oname);
int RF[nmax][nmax], A[nmax][nmax];
int n, i, j, k;
int main()
{
fin >> n;
for(i = 1; i <= n; i ++)
for(j = 1; j <= n; j ++)
{
fin >> A[i][j];
if(A[i][j])
RF[i][j] = A[i][j];
else
RF[i][j] = inf;
}
for(k = 1; k <= n; k ++)
for(i = 1; i <= n; i ++)
for(j = 1; j <= n; j ++)
if(A[i][k] && A[k][j] && i != j && i != k && j != k)
RF[i][j] = min(RF[i][j], RF[i][k] + RF[k][j]);
for(i = 1; i <= n; i ++)
{
for(j = 1; j <= n; j ++)
{
if(RF[i][j] == inf)
fout << "0 ";
else
fout << RF[i][j] << " ";
}
fout << "\n";
}
return 0;
}