Cod sursa(job #1205697)

Utilizator abel1090Abel Putovits abel1090 Data 7 iulie 2014 18:30:14
Problema Floyd-Warshall/Roy-Floyd Scor 50
Compilator cpp Status done
Runda Arhiva educationala Marime 0.95 kb
///ROY-FLOYD
#include <fstream>
#include <vector>
#include <limits>
#include <iostream>
using namespace std;

typedef numeric_limits<int> I_LIM;

void royFloyd(vector<vector<int> >& neighMat) {
	unsigned numNodes = neighMat.size();

	for(unsigned k=0; k < numNodes; k++)
		for(unsigned i=0; i < numNodes; i++)
			for(unsigned j=0; j < numNodes; j++)
				if(i != k && k != j && i != j)
					if(neighMat[i][k] + neighMat[k][j] < neighMat[i][j])
						neighMat[i][j] = neighMat[i][k] + neighMat[k][j];
}

int main() {
	ifstream inStr("royfloyd.in");
	ofstream outStr("royfloyd.out");

	unsigned numNodes;
	inStr >> numNodes;

	vector<vector<int> > neighMat(numNodes, vector<int>(numNodes));

	for(unsigned i=0; i < numNodes; i++)
		for(unsigned j=0; j < numNodes; j++)
			inStr >> neighMat[i][j];

	royFloyd(neighMat);

	for(unsigned i=0; i < numNodes; i++) {
		for(unsigned j=0; j < numNodes; j++)
					outStr << neighMat[i][j] << ' ';
		outStr << '\n';
	}

	return 0;
}