Cod sursa(job #875463)

Utilizator jumper007Raul Butuc jumper007 Data 10 februarie 2013 10:47:33
Problema Floyd-Warshall/Roy-Floyd Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.91 kb
#include <iomanip>
#include <fstream>
#include <climits>

using namespace std;

const int Max = 101;
int i, j, k, length, value, local_aux, Cost[Max][Max]/*, Path[Max][Max]*/;

void readData(ifstream& in){
	in >> length;
	for (i = 1; i <= length; i++)
		for (j = 1; j <= length; j++)
			in >> Cost[i][j];
}

void process(){
	for (k = 1; k <= length; k++){
		for (i = 1; i <= length; i++){
			for (j = 1; j <= length; j++){
				if (Cost[i][k] && Cost[k][j] && (Cost[i][j] == 0 || Cost[i][j] > Cost[i][k] + Cost[k][j]) && i != j)
					Cost[i][j] = Cost[i][k] + Cost[k][j];
			}
		}
	}
}

void writeData(ofstream& out){
	for (i = 1; i <= length; i++){
		for (j = 1; j <= length; j++){
				out << Cost[i][j] << " ";
		}
		out << endl;
	}
}

int main(int argc, char *argv[]){
	ifstream in("royfloyd.in");
	ofstream out("royfloyd.out");
	readData(in);
	process();
	writeData(out);
	return 0;
}