Pagini recente » Borderou de evaluare (job #1691974) | Cod sursa (job #1777547)
#include <iostream>
#include <fstream>
#include <climits>
using namespace std;
ifstream f("royfloyd.in");
ofstream g("royfloyd.out");
int dist[101][101];
int n;
int main()
{
f >> n;
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++){
f>> dist[i][j];
if(dist[i][j]==0)
dist[i][j]=INT_MAX/2-1;
}
for(int i=1;i<=n;i++)
dist[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(dist[i][j]>dist[i][k]+dist[k][j])
dist[i][j]=dist[i][k]+dist[k][j];
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++)
g << dist[i][j] << " ";
g<< "\n";
}
return 0;
}