Pagini recente » Cod sursa (job #65551) | Cod sursa (job #1509383) | Cod sursa (job #832373) | Cod sursa (job #960797) | Cod sursa (job #363389)
Cod sursa(job #363389)
#include<fstream>
#include<iostream>
#define inf "royfloyd.in"
#define outf "royfloyd.out"
#define MaxN 101
#define PINF 1.e20
using namespace std;
fstream f(inf,ios::in),g(outf,ios::out);
int N;
float MP[MaxN][MaxN];
void Citire()
{
f>>N;
int i,j;
for(i=1;i<=N;i++)
{
for(j=1;j<=N;j++)
{
f>>MP[i][j];
if(i!=j && MP[i][j]==0)MP[i][j]=PINF;
}
}
}
void RoyFloyd()
{
for(int k=1;k<=N;k++)
{
for(int i=1;i<=N;i++)
{
for(int j=1;j<=N;j++)
if(MP[i][j]>MP[i][k]+MP[k][j])MP[i][j]=MP[i][k]+MP[k][j];
}
}
}
int main()
{
Citire();
RoyFloyd();
for(int i=1;i<=N;i++)
{
for(int j=1;j<=N;j++)
{
if(MP[i][j]==PINF)g<<"0"<<" ";
else g<<MP[i][j]<<" ";
}
g<<endl;
}
f.close();
g.close();
return 0;
}