Pagini recente » Cod sursa (job #538761) | Cod sursa (job #3205397) | Cod sursa (job #1750148) | Cod sursa (job #1004990) | Cod sursa (job #1849168)
#include <bits/stdc++.h>
#define PINF 1000
using namespace std;
ofstream g("royfloyd.out");
const int NMAX = 10;
int n, m;
int mat[NMAX][NMAX];
void constr_mat();
void afisare_mat();
void roy_floyd();
int main()
{
constr_mat();
afisare_mat();
roy_floyd();
g<<"\n";
afisare_mat();
return 0;
}
void constr_mat()
{
//int i, j, x, y, k, c;
ifstream f("royfloyd.in");
f>>n;
/*
f>>n>>m;
for(i = 1; i <= n; i++)
for(j = 1; j <= n; j++)
if(i == j) mat[i][j] = 0;
else mat[i][j] = PINF;
for(k = 1; k <= m; k++)
{
f>>x>>y>>c;
mat[x][y] = mat[y][x] = c;
}
*/
for(int i = 1; i <= n; i++)
for(int j = 1; j <= n; j++)
f>>mat[i][j];
f.close();
}
void afisare_mat()
{
for(int i = 1; i <= n; i++){
for(int j = 1; j <= n; j++)
g<<mat[i][j]<<" ";
g<<"\n";
}
}
void roy_floyd()
{
for(int k = 1; k <= n; k++)
for(int i = 1; i <= n; i++)
for(int j = 1; j <= n; j++)
if(mat[i][j] > mat[i][k] + mat[k][j]) mat[i][j] = mat[i][k] + mat[k][j];
}