Cod sursa(job #1095761)

Utilizator andreifirstCioara Andrei Ioan andreifirst Data 31 ianuarie 2014 20:25:12
Problema Floyd-Warshall/Roy-Floyd Scor 10
Compilator cpp Status done
Runda Arhiva educationala Marime 0.77 kb
#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <iomanip>
#include <cmath>

#define e '\n'

using namespace std;

#define FILE "royfloyd"

#ifdef FILE
	ifstream f(string (string(FILE) + ".in").c_str());
	ofstream g(string (string(FILE) + ".out").c_str());
#endif
#ifndef FILE
	#define f cin
	#define g cout
#endif

int i, j, n, k, x, y;
int v[105][105];


int main() {

	f >> n ;
	for (i=1; i<=n; i++) {
		for (j=1; j<=n; j++) {
			f >> v[i][j];
		}
	}

	for (i=1; i<=n; i++) {
		for (j=1; j<=n; j++) {
			for (k=1; k<=n; k++) {
				if (v[i][k] + v[k][j] < v[i][j]) {
					v[i][j] = v[i][k] + v[k][j];
				}
			}
		}
	}

	for (i=1; i<=n; i++) {
		for (j=1; j<=n; j++) {
			g << v[i][j] << " ";
		}
		g << e;
	}

}