Pagini recente » Cod sursa (job #2650963) | Cod sursa (job #2650291) | Cod sursa (job #2654124) | Cod sursa (job #1033241) | Cod sursa (job #1852734)
#include <fstream>
using namespace std;
ifstream cin("royfloyd.in");
ofstream cout("royfloyd.out");
long long nr, i, j, matrice[1005][1005], k, x, y;
int main()
{
cin >> nr;
for(i=1; i <= nr; i++)
{
for(j=1; j <= nr; j++)
{
cin >> matrice[i][j];
if(matrice[i][j] == 0)
matrice[i][j] = 100000000000;
}
}
for(k=1; k <= nr; k++)
{
for(x=1; x <= nr; x++)
{
for(y=1; y <= nr; y++)
{
if(matrice[x][y] > matrice[x][k] + matrice[k][y])
{
matrice[x][y] = matrice[x][k] + matrice[k][y];
//ft[x][y] = k;
}
}
}
}
for(i=1; i <= nr; i++)
{
for(j=1; j <= nr; j++)
if(i == j || matrice[i][j] == 100000000000)
cout << "0 ";
else
cout << matrice[i][j] << ' ';
cout << '\n';
}
}