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