Pagini recente » Cod sursa (job #2341711) | Cod sursa (job #2345264) | Cod sursa (job #579790) | Cod sursa (job #2094250) | Cod sursa (job #2806452)
#include <iostream>
#include <bits/stdc++.h>
#define inf 1000000
using namespace std;
ifstream in("royfloyd.in");
ofstream out("royfloyd.out");
int n;
int dist[100][100];
int minDist[100][100];
int main()
{
in >> n;
memset(minDist, inf, sizeof(dist));
memset(dist, inf, sizeof(minDist));
for (int i = 0; i < n; i++)
minDist[i][i] = 0;
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
{
in >> dist[i][j];
minDist[i][j] = dist[i][j];
}
for (int k = 0; k < n; k++)
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
//minDist[i][j] = min(min(minDist[i][j], minDist[i][k] + dist[k][j]), dist[i][k] + minDist[k][j]);
minDist[i][j] = min(minDist[i][j], minDist[i][k] + minDist[k][j]);
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
if (minDist[i][j] >= inf)
{
out << 0 << ' ';
continue;
}
else
out << minDist[i][j] << ' ';
out << '\n';
}
return 0;
}