Pagini recente » Cod sursa (job #2449728) | Cod sursa (job #2608020) | Cod sursa (job #1252258) | Cod sursa (job #2202103) | Cod sursa (job #2309441)
#include <fstream>
#include <algorithm>
using namespace std;
ifstream fin("royfloyd.in");
ofstream fout("royfloyd.out");
int n;
int adj[102][102];
int dist[102][102];
int main()
{
fin>>n;
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
{
fin>>adj[i][j];
if(i==j) dist[i][j]=0;
else if(adj[i][j]==0) dist[i][j]=0x3f3f3f3f;
else dist[i][j]=adj[i][j];
}
for(int k=1;k<=n;k++)
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
dist[i][j]=min(dist[i][j],
dist[i][k]+dist[k][j]);
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
fout<<dist[i][j]<<" ";
fout<<"\n";
}
return 0;
}