Pagini recente » Cod sursa (job #2535797) | Cod sursa (job #2938385) | Cod sursa (job #2225131) | Cod sursa (job #2108299) | Cod sursa (job #2700898)
#include <fstream>
using namespace std;
const short NMAX = 100;
const int INF = 1000000000;
ifstream fin("royfloyd.in");
ofstream fout("royfloyd.out");
int mat[NMAX + 5][NMAX + 5];
int main()
{
ios_base::sync_with_stdio(false);
fin.tie(NULL);
fout.tie(NULL);
int n,i,j,k,x;
fin >> n;
for(i = 1; i <= n; i++)
for(j = 1; j <= n; j++)
{
fin >> x;
if(i == j)
mat[i][j] = 0;
else
if(x)
mat[i][j] = x;
else
mat[i][j] = INF;
}
for(k = 1; k <= n; k++)
for(i = 1; i <= n; i++)
for(j = 1; j <= n; j++)
mat[i][j] = min(mat[i][j], mat[i][k] + mat[k][j]);
for(i = 1; i <= n; i++)
{
for(j = 1; j <= n; j++)
if(mat[i][j] == INF)
fout << "0 ";
else
fout << mat[i][j] << " ";
fout << "\n";
}
return 0;
}