Pagini recente » Cod sursa (job #86478) | Cod sursa (job #2879128) | Cod sursa (job #2998645) | Cod sursa (job #190381) | Cod sursa (job #871472)
Cod sursa(job #871472)
#include<fstream>
using namespace std;
ifstream in("royfloyd.in");
ofstream out("royfloyd.out");
int n,i,j,k,a[101][101];
int main()
{
in>>n;
for (i=1;i<=n;i++)
for (j=1;j<=n;j++)
in>>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][k]!=0 && a[k][j]!=0)
if (a[i][k]+a[k][j]<a[i][j] || a[i][j]==0)
a[i][j]=a[i][k]+a[k][j];
for (i=1;i<=n;i++)
{
for (j=1;j<=n;j++)
out<<a[i][j]<<' ';
out<<'\n';
}
}