Cod sursa(job #1237092)

Utilizator DenisacheDenis Ehorovici Denisache Data 3 octombrie 2014 09:05:44
Problema Floyd-Warshall/Roy-Floyd Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.23 kb
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <stack>
#include <queue>
#include <list>
//#include <windows.h>
//#include <conio.h>
#include <cstdlib>
#include <time.h>
#include <limits.h>
#include <string>
#include <math.h>
using namespace std;
#define forA(V,it) for (typeof(V.begin()) it=V.begin();it!=V.end();it++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define ull unsigned ll
#define MOD 1000000007
#define INF (1<<31)-1
#define MINF -(1<<31)
#define vi vector <int>
#define vll vector <ll>
#define pii pair <int,int>
#define pll pair <ll,ll>
#define newl printf("\n")
#define DIM 1000000
int i,j,k,w[105][105],N;
int main()
{
    freopen("royfloyd.in","r",stdin);
    freopen("royfloyd.out","w",stdout);
    scanf("%d",&N);
    for (i=1;i<=N;i++) for (j=1;j<=N;j++) scanf("%d",&w[i][j]);
    for (k=1;k<=N;k++)
        for (i=1;i<=N;i++)
            for (j=1;j<=N;j++)
                if ((w[i][k]+w[k][j]<w[i][j] || !w[i][j]) && i!=j && w[i][k] && w[k][j]) w[i][j]=w[i][k]+w[k][j];
    for (i=1;i<=N;i++,newl)
        for (j=1;j<=N;j++) printf("%d ",w[i][j]);
    return 0;
}