Pagini recente » Cod sursa (job #2844898) | Cod sursa (job #1349849) | Cod sursa (job #1974842) | Cod sursa (job #1974843) | Cod sursa (job #3192643)
#include <fstream>
using namespace std;
ifstream fin ("royfloyd.in");
ofstream fout ("royfloyd.out");
const int NMAX = 100;
const int INF = 1e8;
int n;
long long c[NMAX + 1][NMAX + 1];
int main()
{
fin >> n;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++) {
fin >> c[i][j];
if(c[i][j]==0)
c[i][j] = INF;
}
for (int z = 1; z <= n; z++)
for (int x = 1; x <= n; x++)
for (int y = 1; y <= n; y++){
if ( c[x][z] + c[z][y] < c[x][y])
c[x][y] = c[x][z] + c[z][y];
}
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= n; j++)
if ( (i == j) ||c[i][j] >= INF)
fout << 0 << ' ';
else fout << c[i][j] << ' ';
fout << '\n';
}
return 0;
}