Pagini recente » Cod sursa (job #176216) | Cod sursa (job #3258028) | Cod sursa (job #3271708) | Cod sursa (job #517022) | Cod sursa (job #229602)
Cod sursa(job #229602)
#include<fstream>
#include<iostream>
using namespace std;
int main()
{
ifstream fin("royfloyd.in");
ofstream fout("royfloyd.out");
int mat[100][100];
int n;
fin>>n;
for(int i = 0; i<n; i++)
for(int j = 0; j<n; j++) fin>>mat[i][j];
for(int k=0; k<n; k++)
for(int i=0; i<n; i++)
for(int j=0; j<n; j++)
if((mat[i][k]>0) && (mat[k][j]>0) )
if( i!=j )
if( mat[i][j]==0 )
mat[i][j] = mat[i][k]+mat[k][j];
else
mat[i][j] = min(mat[i][j],mat[i][k]+mat[k][j]);
for(int i=0; i<n; i++)
{
for(int j=0; j<n; j++)
fout<<mat[i][j]<<" ";
fout<<endl;
}
fout.close();
return 0;
}