Cod sursa(job #1771967)

Utilizator HumanoiDkiki123123 HumanoiD Data 6 octombrie 2016 12:40:47
Problema Floyd-Warshall/Roy-Floyd Scor 10
Compilator cpp Status done
Runda Arhiva educationala Marime 1.23 kb
#include <bits/stdc++.h>
using namespace std;
#define Nmax 111
#define inf 0x3f3f3

class DirectedGraph {
    private :
        int nodes;
        int dist[Nmax][Nmax];

    public :
        DirectedGraph(int n){
            this->nodes = n;
            memset(dist,inf,sizeof dist);
        }

        void setCost (int from,int to,int cost){
            dist[from][to] = cost;
        }

        void royFloyd(){
            int n = this->nodes;
            for (int i=0;i<n;++i)
                for (int j=0;j<n;++j)
                    for (int k=0;k<n;++k)
                        dist[i][j] = min(dist[i][j],dist[i][k] + dist[k][j]);
            }

        int getDist(int i,int j){
            return dist[i][j];
        }
    };

int main(void){
    ifstream cin("royfloyd.in");
    ofstream cout("royfloyd.out");
    int n,aux;
    cin>>n;
    DirectedGraph *graph = new DirectedGraph(n);
    for (int i=0;i<n;++i){
        for (int j=0;j<n;++j){
            cin>>aux;
            graph->setCost(i,j,aux);
        }
    }
    graph->royFloyd();
    for (int i=0;i<n;++i){
        for (int j=0;j<n;++j){
            cout<<graph->getDist(i,j)<<" ";
        }
        cout<<"\n";
    }
    return 0;
}