Pagini recente » Cod sursa (job #1377972) | Cod sursa (job #1294108) | Cod sursa (job #517345) | Cod sursa (job #2469235) | Cod sursa (job #2886742)
#include <iostream>
#include <fstream>
using namespace std;
const string filename = "royfloyd";
ifstream fin(filename + ".in");
ofstream fout(filename + ".out");
const int inf = 0x3f3f3f3f;
int n, dist[105][105];
int main()
{
fin >> n;
for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= n; j++)
{
fin >> dist[i][j];
if(dist[i][j] == 0 && i != j)
dist[i][j] = inf;
}
}
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++)
{
if(dist[i][j] == inf)
dist[i][j] = 0;
fout << dist[i][j] << ' ';
}
fout << '\n';
}
return 0;
}