Cod sursa(job #2080664)

Utilizator IulianBobocBoboc Iulian IulianBoboc Data 3 decembrie 2017 13:42:16
Problema Floyd-Warshall/Roy-Floyd Scor 50
Compilator cpp Status done
Runda Arhiva educationala Marime 0.75 kb
#include<iostream>
#include<fstream>
using namespace std;
#define maxConst 100
int weight[maxConst][maxConst];

int main() {
	ifstream inFile("royfloyd.in");
	ofstream outFile("royfloyd.out");

	int n, i, j, k;
	inFile >> n;
	for (i = 0; i < n; ++i) {
		for (j = 0; j < n; ++j) {
			inFile >> weight[i][j];
		}
	}


	for (k = 0; k < n; ++k) {
		for (i = 0; i < n; ++i) {
			for (j = 0; j < n; ++j) {
				if (weight[i][k] > 0 && weight[k][j] > 0 && weight[i][j] > weight[i][k] + weight[k][j]) {
					weight[i][j] = weight[i][k] + weight[k][j];
				}
			}
		}
	}

	for (i = 0; i < n; ++i) {
		for (j = 0; j < n; ++j) {
			outFile << weight[i][j] << " ";
		}
		outFile << "\n";
	}

	inFile.close();
	outFile.close();
	return 0;
}