Pagini recente » Cod sursa (job #2695984) | Cod sursa (job #1733065) | Cod sursa (job #1884891) | Monitorul de evaluare | Cod sursa (job #1435271)
#include <iostream>
#include <fstream>
#define INPUT_FILE "royfloyd.in"
#define OUTPUT_FILE "royfloyd.out"
#define MAX_SIZE 100
#define ALMOST_INFINITY 123456789
std::fstream in(INPUT_FILE, std::fstream::in);
std::fstream out(OUTPUT_FILE, std::fstream::out);
using namespace std;
int main(int argc, char const *argv[])
{
register int i, j, k;
int node_count;
int cost_matrix[MAX_SIZE][MAX_SIZE];
in >> node_count;
for(i = 0; i < node_count; i++) {
for (j = 0; j < node_count; j++) {
in >> cost_matrix[i][j];
if (cost_matrix[i][j] == 0 && i != j) {
cost_matrix[i][j] = ALMOST_INFINITY;
}
}
}
for (k = 0; k < node_count; k++) {
for (i = 0; i < node_count; i++) {
for (j = 0; j < node_count; j++) {
if (cost_matrix[i][j] > cost_matrix[i][k] + cost_matrix[k][j] && (i != j) && (i != k) && (j != k)) {
cost_matrix[i][j] = cost_matrix[i][k] + cost_matrix[k][j];
}
}
}
}
for(i = 0; i < node_count; i++) {
for (j = 0; j < node_count; j++) {
out << cost_matrix[i][j] << " ";
}
out << "\n";
}
out.close();
in.close();
return 0;
}