Pagini recente » Cod sursa (job #1284210) | Cod sursa (job #49139) | Cod sursa (job #3200186) | Cod sursa (job #3257522) | Cod sursa (job #2999621)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("royfloyd.in");
ofstream fout("royfloyd.out");
int mat[105][105],n,m,cost[105][105],pret;
const int inf=2000000001;
void citire()
{
fin>>n;
int x,y;
for(int i=1; i<=n; i++)
{
for(int j=1; j<=n; j++)
{
fin>>pret;
if(pret!=0)
cost[i][j]=pret;
else if(i==j)
cost[i][j]=0;
else cost[i][j]=inf;
}
}
}
void roy()
{
for(int k=1; k<=n; k++)
{
for(int i=1; i<=n; i++)
{
for(int j=1; j<=n; j++)
{
if(cost[i][k]!=inf && cost[k][j]!=inf && cost[i][k]+cost[k][j]<cost[i][j])
cost[i][j]=cost[i][k]+cost[k][j];
}
}
}
}
int main()
{
citire();
roy();
for(int i=1; i<=n; i++)
{
for(int j=1; j<=n; j++)
{
if(cost[i][j]==inf)
fout<<0<<" ";
else fout<<cost[i][j]<<" ";
}
fout<<'\n';
}
return 0;
}