Cod sursa(job #1355183)

Utilizator viuscenkoViktor Iuscenko viuscenko Data 22 februarie 2015 14:49:20
Problema Floyd-Warshall/Roy-Floyd Scor 50
Compilator cpp Status done
Runda Arhiva educationala Marime 1.3 kb
#include <bits/stdc++.h>

using namespace std;

#define     mp              make_pair
#define     fs              first
#define     sc              second
#define     pob             pop_back
#define     pub             push_back
#define     eps             1E-7
#define     sz(a)           a.size()
#define     count_one       __builtin_popcount;
#define     count_onell     __builtin_popcountll;
#define     fastIO          ios_base::sync_with_stdio(false)
#define     PI              (acos(-1.0))
#define     linf            (1LL<<62)//>4e18
#define     inf             (0x7f7f7f7f)//>2e9

#define NMAX 100
#define DEBUG 1
#ifdef DEBUG
#define D(x) x
#else
#define D(x)
#endif

ifstream f("royfloyd.in");
ofstream g("royfloyd.out");

int N;
int in[NMAX][NMAX];
int d[NMAX][NMAX];

int main()
{
    f >> N;

    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < N; ++j) {
        	f >> d[i][j];// = in[i][j];
        }
    }

    for (int k = 0; k < N; k++) {
    	for (int i = 0; i < N; i++) {
    		for (int j = 0; j < N; j++) {
    			if (d[i][j] > d[i][k] + d[k][j]) {
    				d[i][j] = d[i][k] + d[k][j];
    			}
    		}
    	}
    }

    for (int i = 0; i < N; ++i) {
    	for (int j = 0; j < N; ++j)
    		g << d[i][j] << " ";
        g << "\n";
    }

    return 0;
}