Pagini recente » Cod sursa (job #669127) | Cod sursa (job #3322489) | Cod sursa (job #2928542) | Cod sursa (job #2936159) | Cod sursa (job #3321933)
#include <fstream>
std::ifstream in("royfloyd.in");
std::ofstream out("royfloyd.out");
typedef unsigned short node_t;
using std::min;
int main() {
node_t N;
in >> N;
node_t graph[100][100];
node_t dist[100][100];
for(node_t a = 0; a < N; a += 1) {
for(node_t b = 0; b < N; b += 1) {
in >> graph[a][b];
dist[a][b] = graph[a][b] ? graph[a][b] : 2000;
}
}
for(node_t mid = 0; mid < N; mid += 1) {
for(node_t a = 0; a < N; a += 1) {
for(node_t b = 0; b < N; b += 1) {
dist[a][b] = min<node_t>(dist[a][b], dist[a][mid] + dist[mid][b]);
}
}
}
for(node_t a = 0; a < N; a += 1) {
for(node_t b = 0; b < N; b += 1) {
out << ( dist[a][b] * (dist[a][b] != 2000) ) << ' ';
}
out << '\n';
}
}