Pagini recente » Cod sursa (job #3276219) | Cod sursa (job #1949423) | Cod sursa (job #3279496) | Cod sursa (job #2972622) | Cod sursa (job #3278453)
#include <fstream>
#include <algorithm>
#include <map>
#include <cmath>
using namespace std;
ifstream cin("royfloyd.in");
ofstream cout("royfloyd.out");
int v[105][105];
int n;
int main()
{
cin>>n;
for(int i=1;i<=n;i++)
{
for(int k=1;k<=n;k++)
{
cin>>v[i][k];
}
}
//jik 50
//ijk 10
//jki 50
//
for(int j=1;j<=n;j++)
{
for(int k=1;k<=n;k++)
{
for(int i=1;i<=n;i++)
{
int sum=v[i][j]+v[j][k];
if(v[i][j]==0 || v[j][k]==0)
{
sum=999999;
}
if(v[i][k]==0 && sum!=999999)
{
v[i][k]=sum;
}
v[i][k]=min(v[i][k], sum );
}
}
}
for(int i=1;i<=n;i++)
{
for(int k=1;k<=n;k++)
{
cout<<v[i][k]<<" ";
}
cout<<'\n';
}
return 0;
}
//manuscrisul voinici