Pagini recente » Cod sursa (job #275402) | Cod sursa (job #2199254) | Cod sursa (job #1612885) | Cod sursa (job #3135252) | Cod sursa (job #2574310)
#include <iostream>
#include <fstream>
#define INF 9999999
using namespace std;
ifstream fi("royfloyd.in");
ofstream fo("royfloyd.out");
int n;
int mat[101][101];
int main()
{
fi>>n;
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
{
fi>>mat[i][j];
//if(mat[i][j]==0)
//mat[i][j]=INF;
}
for(int k=1;k<=n;k++)
{
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
if(i!=k && j!=k && i!=j &&
mat[i][j] && mat[i][k] && mat[k][j])
{
if(mat[i][j]>mat[i][k]+mat[k][j])
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]>=INF)
mat[i][j]=0;
fo<<mat[i][j]<<" ";
}
fo<<endl;
}
fi.close();
fo.close();
return 0;
}