Pagini recente » Cod sursa (job #2405578) | Cod sursa (job #1847269) | Cod sursa (job #2151530) | Cod sursa (job #1976209) | Cod sursa (job #2427373)
#include <iostream>
#include <fstream>
#define Nmax 101
using namespace std;
int mat[Nmax][Nmax];
ifstream f("royfloyd.in");
ofstream g("royfloyd.out");
int main()
{
int n;
f >> n;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
f >> mat[i][j];
for (int k = 1; k <= n; k++)
for (int i = 1; i <= n; i++)
for (int j = 0; j <= n; j++)
if ((mat[i][j] == 0 or mat[i][j] > mat[i][k] + mat[k][j]) and mat[i][k] and mat[i][k] and mat[k][j] and i != j)
mat[i][j] = mat[i][k] + mat[k][j];
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= n; j++)
g << mat[i][j] << " ";
g << endl;
}
return 0;
}