Cod sursa(job #2421877)

Utilizator CameliaSSamoilescu Camelia CameliaS Data 16 mai 2019 15:49:34
Problema Floyd-Warshall/Roy-Floyd Scor 50
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.91 kb
#include <iostream>
#include <fstream>
using namespace std;

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

#define inf 100005
#define NMAX 105

int n, dist[NMAX][NMAX];


// j, i+1
void citire(){
    f>>n;
    for(int i = 1 ; i <= n; i ++)
        for(int j = 1; j <= n; j ++)
            f>>dist[i][j];

}

void RoyFloyd(){
    for(int i = 1 ; i <= n; i ++)
        dist[i][i] = 0;
    for(int k = 1; k <= n; k ++)
        for(int i = 1; i <= n; i ++)
            for(int j = 1; j <=n; j++)
            if(i!= j)
                if(dist[i][k] + dist[k][j] < dist[i][j] )
                    dist[i][j] = dist[i][k] + dist[k][j];


}

void afisare(){
    for(int i = 1 ; i <= n; i ++)
       {
        for(int j = 1; j <= n; j ++)
                g<<dist[i][j]<< " ";
        g<<endl;
       }
}

int main()
{
    citire();
    RoyFloyd();
    afisare();
    return 0;
}