Pagini recente » Cod sursa (job #3287689) | Cod sursa (job #2294606) | Cod sursa (job #2206351) | Cod sursa (job #2034565) | Cod sursa (job #2839026)
#include <fstream>
#include <vector>
using namespace std;
ifstream fin("royfloyd.in");
ofstream fout("royfloyd.out");
const int oo = 2e9;
int n, x, y, mat[101][101], i, j, k;
int main()
{
fin >> n;
for (i = 1; i <= n; i++)
for (j = 1; j <= n; j++)
{
fin >> mat[i][j];
if (mat[i][j] == 0 && i != j) mat[i][j] = oo;
}
for (k = 1; k <= n; k++)
for (i = 1; i <= n; i++)
for (j = 1; j <= n; j++)
if (mat[i][j] > mat[i][k] + mat[k][j])
mat[i][j] = mat[i][k] + mat[k][j];
for (i = 1; i <= n; i++, fout << "\n")
for (j = 1; j <= n; j++)
fout << mat[i][j] * (mat[i][j] != oo) << ' ';
return 0;
}