Pagini recente » Diferente pentru problema/alee intre reviziile 14 si 15 | Cod sursa (job #2629364) | Diferente pentru problema/nkbiti intre reviziile 5 si 6 | Cod sursa (job #2577734) | Cod sursa (job #2838061)
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("royfloyd.in");
ofstream fout("royfloyd.out");
const int MAX=105;
const int INF=1e9;
int n,mat[MAX][MAX];
int main()
{
fin >> n;
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
{
fin >> mat[i][j];
if(i!=j && 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(mat[i][k]+mat[k][j]<mat[i][j])
mat[i][j]=mat[i][k]+mat[k][j];
for(int i=1;i<=n;i++, fout << '\n')
for(int j=1;j<=n;j++)
if(mat[i][j]==INF)
fout << "0 ";
else
fout << mat[i][j] << " ";
return 0;
}