Cod sursa(job #1435269)

Utilizator agamanAlexandru Gaman agaman Data 12 mai 2015 18:53:11
Problema Floyd-Warshall/Roy-Floyd Scor 50
Compilator cpp Status done
Runda Arhiva educationala Marime 0.95 kb
#include <iostream>
#include <fstream>

#define INPUT_FILE "royfloyd.in"
#define OUTPUT_FILE "royfloyd.out"

#define MAX_SIZE 100

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];
		}
	}

	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;
}