Pagini recente » Cod sursa (job #2777525) | Cod sursa (job #706723) | Cod sursa (job #3234261) | Cod sursa (job #2032015) | Cod sursa (job #1849171)
#include <bits/stdc++.h>
#define PINF 1000
using namespace std;
ofstream g("royfloyd.out");
const int NMAX = 100;
int n, m;
int mat[NMAX][NMAX];
void constr_mat();
void afisare_mat();
void roy_floyd();
int main()
{
constr_mat();
//afisare_mat();
roy_floyd();
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]) && i != k && j != k) mat[i][j] = mat[i][k] + mat[k][j];
}