Pagini recente » Cod sursa (job #1374895) | Cod sursa (job #1899466) | Cod sursa (job #1429035) | Cod sursa (job #2308084) | Cod sursa (job #2170281)
#include <fstream>
using namespace std;
const int maxi=15000;
int c[101][101],n,m;
ifstream f("royfloyd.in");
ofstream g("royfloyd.out");
void citire()
{
int x,y,cost;
f >> n;
for(int i=1; i<=n; i++)
for(int j=1; j<=n; j++)
f>>c[i][j];
}
void rf()
{
for(int k=1; k<=n; k++)
for(int i=1; i<=n; i++)
for(int j=1; j<=n; j++)
if( c[i][j] > c[i][k] + c[k][j] )
c[i][j] = c[i][k] + c[k][j];
}
void afis()
{
for(int i=1; i<=n; i++)
{
for(int j=1; j<=n; j++)
if( c[i][j] == maxi ) g<<"-1 ";
else g << c[i][j] <<" ";
g<<endl;
}
}
int main()
{ citire();
rf();
afis();
}