Pagini recente » Cod sursa (job #762341) | Cod sursa (job #1904935) | Cod sursa (job #980699) | Cod sursa (job #1375560) | Cod sursa (job #3217727)
#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) {
if(!dist[i][j] || !dist[i][k] || !dist[k][j])
continue;
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;
}