Cod sursa(job #766833)

Utilizator SzakatsSzakats Istvan Szakats Data 12 iulie 2012 12:26:47
Problema Floyd-Warshall/Roy-Floyd Scor 50
Compilator cpp Status done
Runda Arhiva educationala Marime 1.08 kb
#if 1
#include <stdio.h>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <stdio.h>
#include <iostream>
#include <algorithm>
using namespace std;

#ifdef _WIN32
#define TYPEOF decltype
#else
#define TYPEOF typeof
#endif

#define FOR(i,s,e) for(int i = s;i < e; i++)
#define TR(i, c) for(TYPEOF(c.begin()) i = c.begin(); i != c.end(); ++i)
#define TRS(i, c, ...) TR(__itr, c) { TYPEOF(*c.begin()) &i = *__itr;  __VA_ARGS__ }
#define TRP(f, s, c, ...) TR(__itr, c) { TYPEOF(c.begin()->first) &f = __itr->first; TYPEOF(c.begin()->second) &s = __itr->second;  __VA_ARGS__ }

int main()
{
#if 1
	freopen("royfloyd.in", "r", stdin);
	freopen("royfloyd.out", "w", stdout);
#endif

	int n;
	scanf("%d", &n);

	int a[100][100];

	FOR(i,0,n) {
		FOR(j,0,n) {
			scanf("%d", &a[i][j]);
		}
	}

	FOR(k,0,n) {
		FOR(i,0,n) {
			FOR(j,0,n) {
				if(i != j && a[i][k] + a[k][j] < a[i][j])
					a[i][j] = a[i][k] + a[k][j];
			}
		}
	}

	FOR(i,0,n) {
		FOR(j,0,n) {
			printf("%d ", a[i][j]);
		}
		printf("\n");
	}



	return 0;
}
#endif