Pagini recente » Cod sursa (job #1568824) | Cod sursa (job #1187906) | Cod sursa (job #831674) | Cod sursa (job #425217) | Cod sursa (job #3217730)
#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 i = 0; i != n; ++i)
for(int32_t j = 0; j != n; ++j)
if(!dist[i][j])
dist[i][j] = MAX_VAL;
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(i != 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)
if(dist[i][j] >= MAX_VAL)
dist[i][j] = 0;
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;
}