Pagini recente » Cod sursa (job #2364461) | Cod sursa (job #394438) | Cod sursa (job #1636033) | Cod sursa (job #608853) | Cod sursa (job #1906892)
#include <iostream>
#include <fstream>
using namespace std;
int n,a[101][101],i,j,k;
ifstream f("royfloyd.in");
ofstream g("royfloyd.out");
int main()
{
f>>n;
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
f>>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[k][j]>0 && a[i][k]>0)
if (a[i][j]==0 || a[i][j]>a[i][k] + a[k][j])
a[i][j]=a[i][k] + a[k][j];
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
g<<a[i][j]<<" ";
g<<"\n";
}
return 0;
}