Pagini recente » Cod sursa (job #2719002) | Cod sursa (job #264929) | Cod sursa (job #2530949) | Cod sursa (job #1803921) | Cod sursa (job #2772571)
// roy floyd warshall pe graf orientat
#include <fstream>
#include <algorithm>
std::ifstream fin ("royfloyd.in");
std::ofstream fout ("royfloyd.out");
int const INF = 1e9;
int const nmax = 105;
int ans[nmax][nmax];
int main() {
int n;
fin >> n;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
int aux;
fin >> aux;
if (aux)
ans[i][j] = aux;
else
ans[i][j] = INF;
}
}
for (int k = 1; k <= n; k++)
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
ans[i][j] = std::min(ans[i][j], ans[i][k] + ans[k][j]);
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
if (i == j)
fout << 0 << " ";
else
fout << ans[i][j] << " ";
}
fout << "\n";
}
return 0;
}