Pagini recente » Cod sursa (job #2030868) | Cod sursa (job #1104056) | Cod sursa (job #2839464) | Cod sursa (job #2280845) | Cod sursa (job #393742)
Cod sursa(job #393742)
using namespace std;
#include<fstream>
int n,a[103][103];
int main()
{
int k,i,j;
ifstream fin("royfloyd.in");
fin>>n;
for(i=1;i<=n;++i)
for(j=1;j<=n;++j)
fin>>a[i][j];
for(k=1;k<=n;++k)
for(i=1;i<=n;++i)
for(j=1;j<=n;++j)
if(i!=j&&(a[i][j]>a[i][k]+a[k][j]||a[i][j]==0)&&a[i][k]&&a[k][j])
{
a[i][j]=a[i][k]+a[k][j];
}
ofstream fout("royfloyd.out");
for(i=1;i<=n;++i)
{
for(j=1;j<=n;++j)
fout<<a[i][j]<<' ';
fout<<'\n';
}
return 0;
}