Cod sursa(job #1444418)

Utilizator deresurobertoFMI - Deresu Roberto deresuroberto Data 29 mai 2015 19:12:08
Problema Floyd-Warshall/Roy-Floyd Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.98 kb
//Deresu Roberto - FMI
//Re :)
#include <fstream>
#define nx 107
using namespace std;
int a[nx][nx], n;

ifstream fin("royfloyd.in");
ofstream fout("royfloyd.out");

void Read()
{
    fin >> n;

    for(int i = 1; i <= n; i++)
    {
        for(int j = 1; j <= n; j++)
        {
            fin >> a[i][j];
        }
    }
}

void RoyFloyd()
{
    for(int i = 1; i <= n; i++)
    {
        for(int j = 1; j <= n; j++)
        {
            for(int k = 1; k <= n; k++)
            {
                if(j != k && a[j][i] != 0 && a[i][k] != 0 && (a[j][k] > a[j][i]+a[i][k] || a[j][k] == 0))
                {
                    a[j][k] = a[j][i]+a[i][k];
                }
            }
        }
    }
}

void Print()
{
    for(int i = 1; i <= n; i++)
    {
        for(int j = 1; j <= n; j++)
        {
            fout << a[i][j];
        }

        printf("\n");
    }
}

int main()
{
    Read();
    RoyFloyd();
    Print();

    return 0;
}