Pagini recente » Cod sursa (job #337706) | Cod sursa (job #1751619) | Cod sursa (job #1997485) | Cod sursa (job #422867) | Cod sursa (job #2394390)
#include <iostream>
#include <fstream>
#include <bits/stdc++.h>
#include <map>
const int INF=1e9;
using namespace std;
int N,i,j,a;
int **cost;
void royFloyd()
{
for(i=1;i<=N;i++)
{
cost[i][i]=0;
}
for(int k=1;k<=N;k++)
for(int i=1;i<=N;i++)
for(int j=1;j<=N;j++)
{
if(cost[i][j]>cost[i][k]+cost[k][j])
{
cost[i][j]=cost[i][k]+cost[k][j];
}
}
}
int main()
{
ifstream fin("royfloyd.in");
ofstream fout("royfloyd.out");
fin>>N;
cost=new int*[N];
for(i=1;i<=N;i++)
{
cost[i]=new int[N];
}
for(i=1;i<=N;i++)
for(j=1;j<=N;j++)
{
fin>>a;
if(a==0)
cost[i][j]=INF;
else
cost[i][j]=a;
}
royFloyd();
for(i=1;i<=N;i++)
{
for(j=1;j<=N;j++)
{
fout<<cost[i][j]<<' ';
}
fout<<'\n';
}
fin.close();
fout.close();
return 0;
}