Pagini recente » Cod sursa (job #2793832) | Cod sursa (job #1707535) | Cod sursa (job #2421018) | Cod sursa (job #1707435) | Cod sursa (job #2758499)
#include <iostream>
#include <fstream>
#include <climits>
using namespace std;
ifstream f ("royfloyd.in");
ofstream g ("royfloyd.out");
int n, mat[101][101];
int main()
{
f>>n;
for(int i=1; i<=n; i++)
for(int j=1; j<=n; j++)
{
f>>mat[i][j];
if(mat[i][j]==0 && i!=j) mat[i][j]=INT_MAX/2;
}
for(int k=1; k<=n; k++)
for(int i=1; i<=n; i++)
for(int j=1; j<=n; j++)
{
mat[i][j]=min(mat[i][j], mat[i][k]+mat[k][j]);
}
for(int i=1; i<=n; i++)
{
for(int j=1; j<=n; j++)
{
if(mat[i][j]==INT_MAX/2)
g<<0<<' ';
else
g<<mat[i][j]<<' ';
}
g<<'\n';
}
return 0;
}