Pagini recente » Cod sursa (job #1155647) | Cod sursa (job #1391206) | Cod sursa (job #1953687) | Cod sursa (job #292247) | Cod sursa (job #3217728)
#include <iostream>
#include <fstream>
#include <stdint.h>
int32_t min(int32_t x, int32_t y) {
return (x < y) ? x : y;
}
const int32_t MAX_N = 100;
const int32_t MAX_VAL = 1000000;
int32_t dist[MAX_N][MAX_N];
int main() {
std::ifstream fin("royfloyd.in");
std::ofstream fout("royfloyd.out");
int32_t n;
fin >> n;
for(int32_t i = 0; i != n; ++i)
for(int32_t j = 0; j != n; ++j)
fin >> dist[i][j];
for(int32_t k = 0; k != n; ++k)
for(int32_t i = 0; i != n; ++i)
for(int32_t j = 0; j != n; ++j)
dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
for(int32_t i = 0; i != n; ++i) {
for(int32_t j = 0; j != n; ++j)
fout << dist[i][j] << ' ';
fout << '\n';
}
fin.close();
fout.close();
return 0;
}